BhumikaMak commited on
Commit
449b9ac
·
verified ·
1 Parent(s): 43b1616

thread support for concurrent execution

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,12 +1,17 @@
 
 
 
1
  import netron
 
2
  import gradio as gr
3
  import os
4
- import threading
5
  from PIL import Image
6
  import cv2
7
  import numpy as np
8
  from yolov5 import xai_yolov5
9
  from yolov8 import xai_yolov8s
 
 
10
 
11
  # Sample images directory
12
  sample_images = {
@@ -21,7 +26,7 @@ def load_sample_image(sample_name):
21
  return Image.open(image_path)
22
  return None
23
 
24
- def process_image(sample_choice, uploaded_image, yolo_versions, result_callback):
25
  """Process the image using selected YOLO models."""
26
  if uploaded_image is not None:
27
  image = uploaded_image # Use the uploaded image
@@ -40,9 +45,9 @@ def process_image(sample_choice, uploaded_image, yolo_versions, result_callback)
40
  else:
41
  result_images.append((Image.fromarray(image), f"{yolo_version} not yet implemented."))
42
 
43
- result_callback(result_images)
44
 
45
- def view_model(selected_models, netron_callback):
46
  """Generate Netron visualization for the selected models."""
47
  for model in selected_models:
48
  if model == "yolov5":
@@ -54,9 +59,8 @@ def view_model(selected_models, netron_callback):
54
  frameborder="0">
55
  </iframe>
56
  """
57
- netron_callback(iframe_html)
58
- return
59
- netron_callback("<p>Please select a valid model for Netron visualization.</p>")
60
 
61
  # Custom CSS for styling (optional)
62
  custom_css = """
@@ -120,8 +124,6 @@ with gr.Blocks(css=custom_css) as interface:
120
  inputs=sample_selection,
121
  outputs=sample_display,
122
  )
123
-
124
- # Parallel execution with threading
125
  def run_both(sample_choice, uploaded_image, selected_models):
126
  results = []
127
  netron_html = ""
@@ -150,6 +152,7 @@ with gr.Blocks(css=custom_css) as interface:
150
  outputs=[],
151
  )
152
 
 
153
  # Launching Gradio app
154
  if __name__ == "__main__":
155
- interface.launch(share=True)
 
1
+ I want to run process_image and view model together as soon as run button is clicked
2
+
3
+
4
  import netron
5
+ import threading
6
  import gradio as gr
7
  import os
 
8
  from PIL import Image
9
  import cv2
10
  import numpy as np
11
  from yolov5 import xai_yolov5
12
  from yolov8 import xai_yolov8s
13
+ import time
14
+ import tempfile
15
 
16
  # Sample images directory
17
  sample_images = {
 
26
  return Image.open(image_path)
27
  return None
28
 
29
+ def process_image(sample_choice, uploaded_image, yolo_versions):
30
  """Process the image using selected YOLO models."""
31
  if uploaded_image is not None:
32
  image = uploaded_image # Use the uploaded image
 
45
  else:
46
  result_images.append((Image.fromarray(image), f"{yolo_version} not yet implemented."))
47
 
48
+ return result_images
49
 
50
+ def view_model(selected_models):
51
  """Generate Netron visualization for the selected models."""
52
  for model in selected_models:
53
  if model == "yolov5":
 
59
  frameborder="0">
60
  </iframe>
61
  """
62
+ return iframe_html
63
+ return "<p>Please select a valid model for Netron visualization.</p>"
 
64
 
65
  # Custom CSS for styling (optional)
66
  custom_css = """
 
124
  inputs=sample_selection,
125
  outputs=sample_display,
126
  )
 
 
127
  def run_both(sample_choice, uploaded_image, selected_models):
128
  results = []
129
  netron_html = ""
 
152
  outputs=[],
153
  )
154
 
155
+
156
  # Launching Gradio app
157
  if __name__ == "__main__":
158
+ interface.launch(share=True)