BhumikaMak commited on
Commit
173d15f
·
verified ·
1 Parent(s): 8f2fa02
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -122,25 +122,36 @@ with gr.Blocks(css=custom_css) as 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
 
122
  outputs=sample_display,
123
  )
124
 
125
+ # Multi-threaded processing
126
+ def run_both(sample_choice, uploaded_image, selected_models):
127
+ results = []
128
+ netron_html = ""
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
+ # Launch threads
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, netron_html
 
 
149
 
150
  # Run button click
151
  run_button.click(
152
+ fn=run_both,
153
  inputs=[sample_selection, upload_image, selected_models],
154
+ outputs=[result_gallery, netron_display],
155
  )
156
 
157
  # Launch Gradio interface