BhumikaMak commited on
Commit
e92a893
·
verified ·
1 Parent(s): b8aab6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -159,29 +159,22 @@ if __name__ == "__main__":
159
  interface.launch(share=True)
160
  """
161
 
162
-
163
  import gradio as gr
164
- import torch
165
- from ultralytics import YOLO
166
  import os
167
 
168
- # Assuming the YOLOv5 model is located in the same directory as this script
169
- model_path = os.path.join(os.getcwd(), "weight_files/yolov5.onnx") # Replace with the actual model directory name
170
-
171
- def visualize_yolov5():
172
  """
173
- Visualizes the given YOLOv5 model using Netron.
 
 
 
174
  """
175
  try:
176
- # Load the YOLOv5 model
177
- model = YOLO(model_path)
178
-
179
- # Extract the PyTorch model
180
- pytorch_model = model.model
181
-
182
- # Save the PyTorch model to a temporary file
183
- temp_model_path = "temp_model"
184
- torch.save(pytorch_model.state_dict(), os.path.join(temp_model_path, "pytorch_model.bin"))
185
 
186
  # Run Netron
187
  os.system(f"netron {temp_model_path}")
@@ -191,12 +184,12 @@ def visualize_yolov5():
191
 
192
  # Create the Gradio interface
193
  iface = gr.Interface(
194
- fn=visualize_yolov5,
195
- inputs=None, # No input required
196
  outputs="text",
197
- title="Netron YOLOv5 Model Visualization",
198
- description="Visualize the YOLOv5 model."
199
  )
200
 
201
- # Launch the Gradio app with public link
202
  iface.launch(share=True)
 
159
  interface.launch(share=True)
160
  """
161
 
 
162
  import gradio as gr
163
+ import onnxruntime
 
164
  import os
165
 
166
+ def visualize_onnx_model(onnx_model_path):
 
 
 
167
  """
168
+ Visualizes the given ONNX model using Netron.
169
+
170
+ Args:
171
+ onnx_model_path: The path to the ONNX model file.
172
  """
173
  try:
174
+ # Save the ONNX model to a temporary file (optional, but can be helpful)
175
+ temp_model_path = "temp_model.onnx"
176
+ with open(temp_model_path, "wb") as f:
177
+ f.write(onnx_model_path.read()) # Assuming onnx_model_path is a file-like object
 
 
 
 
 
178
 
179
  # Run Netron
180
  os.system(f"netron {temp_model_path}")
 
184
 
185
  # Create the Gradio interface
186
  iface = gr.Interface(
187
+ fn=visualize_onnx_model,
188
+ inputs="file", # Accept the ONNX model as a file upload
189
  outputs="text",
190
+ title="Netron ONNX Model Visualization",
191
+ description="Upload an ONNX model file to visualize with Netron."
192
  )
193
 
194
+ # Launch the Gradio app
195
  iface.launch(share=True)