Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ def create_app():
|
|
13 |
controls = create_filter_controls()
|
14 |
filter_names = list(registry.filters.keys())
|
15 |
|
|
|
|
|
16 |
with gr.Row():
|
17 |
with gr.Column():
|
18 |
input_image = gr.Image(label="Input Image", type="numpy")
|
@@ -23,9 +25,12 @@ def create_app():
|
|
23 |
)
|
24 |
|
25 |
# Thêm các control vào UI
|
26 |
-
control_components = [
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
with gr.Column():
|
31 |
output_image = gr.Image(label="Filtered Image")
|
@@ -33,9 +38,9 @@ def create_app():
|
|
33 |
# Xử lý cập nhật UI
|
34 |
def update_controls(filter_name):
|
35 |
updates = []
|
36 |
-
for
|
37 |
-
visibility =
|
38 |
-
updates.append(
|
39 |
return updates
|
40 |
|
41 |
# Xử lý ảnh real-time
|
@@ -69,12 +74,11 @@ def create_app():
|
|
69 |
filter_select.change(
|
70 |
update_controls,
|
71 |
inputs=filter_select,
|
72 |
-
outputs=list(
|
73 |
)
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
for component in [input_image, filter_select] + control_components_list:
|
78 |
component.change(
|
79 |
process,
|
80 |
inputs=input_components_process,
|
@@ -86,4 +90,4 @@ def create_app():
|
|
86 |
|
87 |
if __name__ == "__main__":
|
88 |
app = create_app()
|
89 |
-
app.launch()
|
|
|
13 |
controls = create_filter_controls()
|
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")
|
|
|
25 |
)
|
26 |
|
27 |
# Thêm các control vào UI
|
28 |
+
control_components = []
|
29 |
+
for filter_name, control_list in controls.items():
|
30 |
+
with gr.Group(visible=filter_name == "Original") as group: # Create group here
|
31 |
+
filter_groups[filter_name] = group # Store group
|
32 |
+
for component in control_list:
|
33 |
+
control_components.append(component) # Collect sliders for event handling
|
34 |
|
35 |
with gr.Column():
|
36 |
output_image = gr.Image(label="Filtered Image")
|
|
|
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 |
+
updates.append(gr.Group.update(visible=visibility, id_to_update=group)) # Update group visibility
|
44 |
return updates
|
45 |
|
46 |
# Xử lý ảnh real-time
|
|
|
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
|
81 |
+
for component in [input_image, filter_select] + control_components: # Attach change to sliders
|
|
|
82 |
component.change(
|
83 |
process,
|
84 |
inputs=input_components_process,
|
|
|
90 |
|
91 |
if __name__ == "__main__":
|
92 |
app = create_app()
|
93 |
+
app.launch(show_error=True)
|