Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,6 +30,7 @@ def create_app():
|
|
| 30 |
for filter_name, group in filter_groups.items():
|
| 31 |
for component in group.children: # Iterate over children of the group
|
| 32 |
control_components.append(component) # Collect sliders for event handling
|
|
|
|
| 33 |
|
| 34 |
with gr.Column():
|
| 35 |
output_image = gr.Image(label="Filtered Image")
|
|
@@ -43,20 +44,17 @@ def create_app():
|
|
| 43 |
return updates
|
| 44 |
|
| 45 |
|
| 46 |
-
# Xử lý ảnh
|
| 47 |
-
def process(*args,
|
| 48 |
-
image = args[0] if len(args) > 0 else None
|
| 49 |
-
filter_name = args[1] if len(args) > 1 else "Original" # Default filter
|
| 50 |
if image is None:
|
| 51 |
return None
|
| 52 |
-
|
| 53 |
try:
|
| 54 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 55 |
-
params = {
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
}
|
| 60 |
|
| 61 |
processed = registry.filters[filter_name](image, **params)
|
| 62 |
|
|
@@ -77,14 +75,13 @@ def create_app():
|
|
| 77 |
outputs=list(filter_groups.values()) # Pass list of groups as outputs
|
| 78 |
)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
)
|
| 88 |
|
| 89 |
return app
|
| 90 |
|
|
|
|
| 30 |
for filter_name, group in filter_groups.items():
|
| 31 |
for component in group.children: # Iterate over children of the group
|
| 32 |
control_components.append(component) # Collect sliders for event handling
|
| 33 |
+
apply_button = gr.Button("Apply Filter") # Add Apply button
|
| 34 |
|
| 35 |
with gr.Column():
|
| 36 |
output_image = gr.Image(label="Filtered Image")
|
|
|
|
| 44 |
return updates
|
| 45 |
|
| 46 |
|
| 47 |
+
# Xử lý ảnh khi button click
|
| 48 |
+
def process(image, filter_name, *args): # Update process function to take image, filter_name and *args
|
|
|
|
|
|
|
| 49 |
if image is None:
|
| 50 |
return None
|
| 51 |
+
|
| 52 |
try:
|
| 53 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 54 |
+
params = {}
|
| 55 |
+
param_names = list(registry.params_map.get(filter_name, {}).keys())
|
| 56 |
+
for i, param_name in enumerate(param_names):
|
| 57 |
+
params[param_name] = args[i] # Get parameter values from args
|
|
|
|
| 58 |
|
| 59 |
processed = registry.filters[filter_name](image, **params)
|
| 60 |
|
|
|
|
| 75 |
outputs=list(filter_groups.values()) # Pass list of groups as outputs
|
| 76 |
)
|
| 77 |
|
| 78 |
+
input_components = [input_image, filter_select] + control_components # Input components for button click
|
| 79 |
+
apply_button.click( # Attach click event to Apply button
|
| 80 |
+
process,
|
| 81 |
+
inputs=input_components, # Use all input components
|
| 82 |
+
outputs=output_image,
|
| 83 |
+
show_progress=False
|
| 84 |
+
)
|
|
|
|
| 85 |
|
| 86 |
return app
|
| 87 |
|