BhumikaMak commited on
Commit
6fb2f90
·
verified ·
1 Parent(s): 91ebe8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -33
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import threading
2
  import gradio as gr
3
  import os
@@ -6,6 +7,8 @@ import cv2
6
  import numpy as np
7
  from yolov5 import xai_yolov5
8
  from yolov8 import xai_yolov8s
 
 
9
 
10
  # Sample images directory
11
  sample_images = {
@@ -42,9 +45,9 @@ def process_image(sample_choice, uploaded_image, yolo_versions):
42
  return result_images
43
 
44
  def view_model(selected_models):
45
- """Generate Netron visualization for the selected models."""
46
- for model in selected_models:
47
  if model == "yolov5":
 
48
  iframe_html = f"""
49
  <iframe
50
  src="https://netron.app/?url=https://huggingface.co/FFusion/FFusionXL-BASE/blob/main/vae_encoder/model.onnx"
@@ -67,31 +70,6 @@ custom_css = """
67
  }
68
  """
69
 
70
- def run_both(sample_choice, uploaded_image, yolo_versions):
71
- """Run both image processing and model visualization simultaneously."""
72
- results = []
73
-
74
- def process_thread():
75
- result_images = process_image(sample_choice, uploaded_image, yolo_versions)
76
- results.append(result_images)
77
-
78
- def model_thread():
79
- model_html = view_model(yolo_versions)
80
- results.append(model_html)
81
-
82
- # Create threads to run both functions simultaneously
83
- process_thread_obj = threading.Thread(target=process_thread)
84
- model_thread_obj = threading.Thread(target=model_thread)
85
-
86
- process_thread_obj.start()
87
- model_thread_obj.start()
88
-
89
- # Wait for both threads to finish
90
- process_thread_obj.join()
91
- model_thread_obj.join()
92
-
93
- return results[0], results[1] # Return processed image results and model visualization
94
-
95
  with gr.Blocks(css=custom_css) as interface:
96
  gr.Markdown("# NeuralVista: Visualize Object Detection of Your Models")
97
 
@@ -137,20 +115,24 @@ with gr.Blocks(css=custom_css) as interface:
137
 
138
  netron_display = gr.HTML(label="Netron Visualization")
139
 
140
- # Update the sample image when the sample is changed
141
  sample_selection.change(
142
  fn=load_sample_image,
143
  inputs=sample_selection,
144
  outputs=sample_display,
145
  )
146
 
147
- # Run both functions concurrently on button click
148
  run_button.click(
149
- fn=run_both,
150
  inputs=[sample_selection, upload_image, selected_models],
151
- outputs=[result_gallery, netron_display],
 
 
 
 
 
 
152
  )
153
 
154
- # Launching Gradio app
155
  if __name__ == "__main__":
156
- interface.launch(share=True)
 
1
+ import netron
2
  import threading
3
  import gradio as gr
4
  import os
 
7
  import numpy as np
8
  from yolov5 import xai_yolov5
9
  from yolov8 import xai_yolov8s
10
+ import time
11
+ import tempfile
12
 
13
  # Sample images directory
14
  sample_images = {
 
45
  return result_images
46
 
47
  def view_model(selected_models):
48
+ for model in selected_models[0]:
 
49
  if model == "yolov5":
50
+ # Embed the Netron viewer using an iframe with the generated URL
51
  iframe_html = f"""
52
  <iframe
53
  src="https://netron.app/?url=https://huggingface.co/FFusion/FFusionXL-BASE/blob/main/vae_encoder/model.onnx"
 
70
  }
71
  """
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  with gr.Blocks(css=custom_css) as interface:
74
  gr.Markdown("# NeuralVista: Visualize Object Detection of Your Models")
75
 
 
115
 
116
  netron_display = gr.HTML(label="Netron Visualization")
117
 
 
118
  sample_selection.change(
119
  fn=load_sample_image,
120
  inputs=sample_selection,
121
  outputs=sample_display,
122
  )
123
 
 
124
  run_button.click(
125
+ fn=process_image,
126
  inputs=[sample_selection, upload_image, selected_models],
127
+ outputs=[result_gallery],
128
+ )
129
+
130
+ selected_models.change(
131
+ fn=view_model,
132
+ inputs=selected_models,
133
+ outputs=netron_display,
134
  )
135
 
136
+ # Launching Gradio app and handling Netron visualization separately.
137
  if __name__ == "__main__":
138
+ interface.launch(share=True)