eienmojiki commited on
Commit
1705ce6
·
verified ·
1 Parent(s): dbdffeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -14,7 +14,6 @@ def create_app():
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():
@@ -28,8 +27,9 @@ def create_app():
28
  # Thêm các control vào UI
29
  control_components = []
30
  for filter_name, control_list in controls.items():
31
- with gr.Group(visible=filter_name == "Original") as group: # Create group here
32
- filter_groups[filter_name] = group # Store group
 
33
  for component in control_list:
34
  control_components.append(component) # Collect sliders for event handling
35
 
@@ -37,14 +37,12 @@ def create_app():
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,8 +74,8 @@ def create_app():
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
 
14
  filter_names = list(registry.filters.keys())
15
 
16
  filter_groups = {} # Store filter groups
 
17
 
18
  with gr.Row():
19
  with gr.Column():
 
27
  # Thêm các control vào UI
28
  control_components = []
29
  for filter_name, control_list in controls.items():
30
+ group = gr.Group(visible=filter_name == "Original") # Create group here, outside with
31
+ filter_groups[filter_name] = group # Store group
32
+ with group: # Put controls inside the group
33
  for component in control_list:
34
  control_components.append(component) # Collect sliders for event handling
35
 
 
37
  output_image = gr.Image(label="Filtered Image")
38
 
39
  # Xử lý cập nhật UI
40
+ def update_controls(filter_name):
 
41
  updates = []
42
  for group_name, group in filter_groups.items():
43
  visibility = (group_name == filter_name)
44
+ updates.append(gr.update(visible=visibility)) # Return list of updates directly
45
+ return updates
 
46
 
47
  # Xử lý ảnh real-time
48
  def process(*args, **kwargs):
 
74
  # Kết nối sự kiện
75
  filter_select.change(
76
  update_controls,
77
+ inputs=filter_select,
78
+ outputs=list(filter_groups.values()) # Pass list of groups as outputs
79
  )
80
 
81
  input_components_process = [input_image, filter_select] + control_components