Spaces:
Sleeping
Sleeping
path change
Browse files
app.py
CHANGED
@@ -161,26 +161,39 @@ if __name__ == "__main__":
|
|
161 |
import gradio as gr
|
162 |
import os
|
163 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
-
#
|
166 |
-
|
167 |
-
|
168 |
-
# Function to visualize the model using Netron
|
169 |
-
def visualize_model():
|
170 |
-
# Serve the model using Netron
|
171 |
-
netron_command = f"netron.start('{MODEL_FILE}', address='0.0.0.0', port=8081)"
|
172 |
-
subprocess.Popen(["python3", "-c", netron_command])
|
173 |
-
# Return the URL where the model is served
|
174 |
-
return f"http://localhost:8081"
|
175 |
|
176 |
-
# Gradio Interface
|
177 |
-
with gr.Blocks() as demo:
|
178 |
-
gr.Markdown("## Model Visualization with Netron")
|
179 |
-
output_link = gr.Textbox(label="Netron Model Link")
|
180 |
-
visualize_btn = gr.Button("Visualize Model")
|
181 |
|
182 |
-
|
183 |
-
|
184 |
|
185 |
-
#
|
186 |
-
demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
import gradio as gr
|
162 |
import os
|
163 |
import subprocess
|
164 |
+
from pathlib import Path
|
165 |
+
|
166 |
+
# Function to visualize the model
|
167 |
+
def visualize_model(model_file):
|
168 |
+
# Save the uploaded file
|
169 |
+
file_path = os.path.join(os.getcwd(), "weight_files/yolov5.onnx")
|
170 |
+
with open(file_path, "wb") as f:
|
171 |
+
f.write(model_file.read())
|
172 |
+
|
173 |
+
# Start Netron server to serve the file
|
174 |
+
port = 8081
|
175 |
+
subprocess.Popen(
|
176 |
+
["netron", "--host", "0.0.0.0", "--port", str(port), file_path],
|
177 |
+
stdout=subprocess.PIPE,
|
178 |
+
stderr=subprocess.PIPE,
|
179 |
+
)
|
180 |
|
181 |
+
# Return URL for visualization
|
182 |
+
netron_url = f"http://localhost:{port}"
|
183 |
+
return f"Model uploaded successfully! View it at: {netron_url}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
+
# Create output directory
|
187 |
+
os.makedirs("./models", exist_ok=True)
|
188 |
|
189 |
+
# Gradio Interface
|
190 |
+
demo = gr.Interface(
|
191 |
+
fn=visualize_model,
|
192 |
+
inputs=gr.File(label="Upload your model file (ONNX, TensorFlow, etc.)"),
|
193 |
+
outputs=gr.Textbox(label="Netron Link"),
|
194 |
+
title="Model Visualizer",
|
195 |
+
description="Upload a model file to visualize its architecture using Netron.",
|
196 |
+
)
|
197 |
+
|
198 |
+
# Launch the app
|
199 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|