Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
165 |
-
from ultralytics import YOLO
|
166 |
import os
|
167 |
|
168 |
-
|
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
|
|
|
|
|
|
|
174 |
"""
|
175 |
try:
|
176 |
-
#
|
177 |
-
|
178 |
-
|
179 |
-
|
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=
|
195 |
-
inputs=
|
196 |
outputs="text",
|
197 |
-
title="Netron
|
198 |
-
description="
|
199 |
)
|
200 |
|
201 |
-
# Launch the Gradio app
|
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)
|