Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,8 @@ def create_app():
|
|
| 14 |
filter_names = list(registry.filters.keys())
|
| 15 |
|
| 16 |
filter_groups = {} # Store filter groups
|
| 17 |
-
|
|
|
|
| 18 |
with gr.Row():
|
| 19 |
with gr.Column():
|
| 20 |
input_image = gr.Image(label="Input Image", type="numpy")
|
|
@@ -36,12 +37,14 @@ def create_app():
|
|
| 36 |
output_image = gr.Image(label="Filtered Image")
|
| 37 |
|
| 38 |
# Xử lý cập nhật UI
|
| 39 |
-
def update_controls(filter_name):
|
|
|
|
| 40 |
updates = []
|
| 41 |
for group_name, group in filter_groups.items():
|
| 42 |
visibility = (group_name == filter_name)
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
# Xử lý ảnh real-time
|
| 47 |
def process(*args, **kwargs):
|
|
@@ -73,8 +76,8 @@ def create_app():
|
|
| 73 |
# Kết nối sự kiện
|
| 74 |
filter_select.change(
|
| 75 |
update_controls,
|
| 76 |
-
inputs=filter_select,
|
| 77 |
-
outputs=list(filter_groups.values())
|
| 78 |
)
|
| 79 |
|
| 80 |
input_components_process = [input_image, filter_select] + control_components
|
|
@@ -90,4 +93,4 @@ def create_app():
|
|
| 90 |
|
| 91 |
if __name__ == "__main__":
|
| 92 |
app = create_app()
|
| 93 |
-
app.launch(share=True
|
|
|
|
| 14 |
filter_names = list(registry.filters.keys())
|
| 15 |
|
| 16 |
filter_groups = {} # Store filter groups
|
| 17 |
+
filter_visibility_state = gr.State({}) # State to store visibility of groups
|
| 18 |
+
|
| 19 |
with gr.Row():
|
| 20 |
with gr.Column():
|
| 21 |
input_image = gr.Image(label="Input Image", type="numpy")
|
|
|
|
| 37 |
output_image = gr.Image(label="Filtered Image")
|
| 38 |
|
| 39 |
# Xử lý cập nhật UI
|
| 40 |
+
def update_controls(filter_name, current_visibility_state):
|
| 41 |
+
visibility_state = {}
|
| 42 |
updates = []
|
| 43 |
for group_name, group in filter_groups.items():
|
| 44 |
visibility = (group_name == filter_name)
|
| 45 |
+
visibility_state[group_name] = visibility
|
| 46 |
+
updates.append(gr.Group.update(visible=visibility)) # Still try to update group visibility
|
| 47 |
+
return visibility_state, updates # Return state and updates
|
| 48 |
|
| 49 |
# Xử lý ảnh real-time
|
| 50 |
def process(*args, **kwargs):
|
|
|
|
| 76 |
# Kết nối sự kiện
|
| 77 |
filter_select.change(
|
| 78 |
update_controls,
|
| 79 |
+
inputs=[filter_select, filter_visibility_state], # Pass state as input
|
| 80 |
+
outputs=[filter_visibility_state, list(filter_groups.values())] # State and groups as output
|
| 81 |
)
|
| 82 |
|
| 83 |
input_components_process = [input_image, filter_select] + control_components
|
|
|
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|
| 95 |
app = create_app()
|
| 96 |
+
app.launch(share=True)
|