Spaces:
Sleeping
Sleeping
concurrent ui component updates
Browse files
app.py
CHANGED
@@ -122,36 +122,25 @@ with gr.Blocks(css=custom_css) as interface:
|
|
122 |
outputs=sample_display,
|
123 |
)
|
124 |
|
125 |
-
#
|
126 |
-
def
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
# Thread to process the image
|
131 |
-
def process_thread():
|
132 |
-
nonlocal results
|
133 |
-
results = process_image(sample_choice, uploaded_image, selected_models)
|
134 |
-
|
135 |
-
# Thread to generate Netron visualization
|
136 |
-
def netron_thread():
|
137 |
-
nonlocal netron_html
|
138 |
netron_html = view_model(selected_models)
|
|
|
139 |
|
140 |
-
|
141 |
-
t1 = threading.Thread(target=process_thread)
|
142 |
-
t2 = threading.Thread(target=netron_thread)
|
143 |
-
t1.start()
|
144 |
-
t2.start()
|
145 |
-
t1.join()
|
146 |
-
t2.join()
|
147 |
|
148 |
-
return results
|
|
|
|
|
149 |
|
150 |
# Run button click
|
151 |
run_button.click(
|
152 |
-
fn=
|
153 |
inputs=[sample_selection, upload_image, selected_models],
|
154 |
-
outputs=[result_gallery
|
155 |
)
|
156 |
|
157 |
# Launch Gradio interface
|
|
|
122 |
outputs=sample_display,
|
123 |
)
|
124 |
|
125 |
+
# Parallel execution with separate updates
|
126 |
+
def process_and_update(sample_choice, uploaded_image, selected_models):
|
127 |
+
"""Handles parallel processing and Netron updates."""
|
128 |
+
# Start Netron visualization in a separate thread
|
129 |
+
def update_netron():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
netron_html = view_model(selected_models)
|
131 |
+
netron_display.update(netron_html) # Update Netron asynchronously
|
132 |
|
133 |
+
threading.Thread(target=update_netron).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
# Process the image in the main thread and return results
|
136 |
+
results = process_image(sample_choice, uploaded_image, selected_models)
|
137 |
+
return results
|
138 |
|
139 |
# Run button click
|
140 |
run_button.click(
|
141 |
+
fn=process_and_update,
|
142 |
inputs=[sample_selection, upload_image, selected_models],
|
143 |
+
outputs=[result_gallery],
|
144 |
)
|
145 |
|
146 |
# Launch Gradio interface
|