BhumikaMak commited on
Commit
bcf0395
·
verified ·
1 Parent(s): f8cb97d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -71
app.py CHANGED
@@ -9,7 +9,7 @@ import numpy as np
9
  from yolov5 import xai_yolov5
10
  from yolov8 import xai_yolov8s
11
  import requests
12
- """
13
  # Sample images directory
14
  sample_images = {
15
  "Sample 1": os.path.join(os.getcwd(), "data/xai/sample1.jpeg"),
@@ -85,13 +85,13 @@ def view_netron_model():
85
 
86
  # Custom CSS for styling (optional)
87
  custom_css = """
88
- #run_button {
89
- # background-color: purple;
90
- # color: white;
91
- # width: 120px;
92
- # border-radius: 5px;
93
- # font-size: 14px;
94
- #}
95
  """
96
 
97
  # Gradio UI
@@ -157,66 +157,3 @@ with gr.Blocks(css=custom_css) as interface:
157
  # Launch Gradio app
158
  if __name__ == "__main__":
159
  interface.launch(share=True)
160
- """
161
- import gradio as gr
162
- import netron
163
- import threading
164
- import time
165
- import tempfile
166
- import os
167
-
168
- # Function to start a Netron server and get the file-based URL
169
- def start_netron_server(file_path):
170
- if not os.path.exists(file_path):
171
- return None
172
-
173
- # Temporary directory to store Netron visualizations
174
- temp_dir = tempfile.mkdtemp()
175
- output_path = os.path.join(temp_dir, "model_view.html")
176
-
177
- # Run Netron in a separate thread with export option
178
- def run_netron():
179
- netron.start(file_path, browse=False, output=output_path)
180
-
181
- thread = threading.Thread(target=run_netron, daemon=True)
182
- thread.start()
183
-
184
- # Wait for Netron to finish initializing
185
- time.sleep(2)
186
-
187
- # Ensure the exported file exists
188
- if os.path.exists(output_path):
189
- return f"file://{output_path}"
190
- else:
191
- return None
192
-
193
-
194
- # Gradio function to display the model viewer
195
- def visualize_model(file):
196
- if file:
197
- file_path = file.name
198
- netron_url = start_netron_server(file_path)
199
- if netron_url:
200
- # Embed the Netron viewer using an iframe with the generated URL
201
- iframe_html = f"""
202
- <iframe
203
- src="{netron_url}"
204
- width="100%"
205
- height="800"
206
- frameborder="0">
207
- </iframe>
208
- """
209
- return iframe_html
210
- return "<p>Error: Unable to generate Netron visualization.</p>"
211
- return "<p>Please upload a valid model file.</p>"
212
-
213
-
214
- # Gradio app
215
- with gr.Blocks() as demo:
216
- gr.Markdown("## Netron Model Viewer with Gradio")
217
- file_input = gr.File(label="Upload a Model File (e.g., ONNX, TFLite, etc.)")
218
- output_html = gr.HTML(label="Model Visualization")
219
- file_input.upload(visualize_model, file_input, output_html)
220
-
221
- # Launch the Gradio app
222
- demo.launch()
 
9
  from yolov5 import xai_yolov5
10
  from yolov8 import xai_yolov8s
11
  import requests
12
+
13
  # Sample images directory
14
  sample_images = {
15
  "Sample 1": os.path.join(os.getcwd(), "data/xai/sample1.jpeg"),
 
85
 
86
  # Custom CSS for styling (optional)
87
  custom_css = """
88
+ run_button {
89
+ background-color: purple;
90
+ color: white;
91
+ width: 120px;
92
+ border-radius: 5px;
93
+ font-size: 14px;
94
+ }
95
  """
96
 
97
  # Gradio UI
 
157
  # Launch Gradio app
158
  if __name__ == "__main__":
159
  interface.launch(share=True)