BhumikaMak commited on
Commit
e24db03
·
verified ·
1 Parent(s): 940b1b1

path change

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -161,26 +161,39 @@ if __name__ == "__main__":
161
  import gradio as gr
162
  import os
163
  import subprocess
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- # Path to the model file (change this to your actual model path)
166
- MODEL_FILE = os.path.join(os.getcwd(), "weight_files/yolov5.onnx")
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
- # On button click, call the function and display the link
183
- visualize_btn.click(fn=visualize_model, inputs=[], outputs=[output_link])
184
 
185
- # Launch the Gradio app
186
- demo.launch(server_name="0.0.0.0", server_port=7860, ssr=False)
 
 
 
 
 
 
 
 
 
 
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)