Spaces:
Sleeping
Sleeping
revert port
Browse files
app.py
CHANGED
@@ -159,55 +159,28 @@ if __name__ == "__main__":
|
|
159 |
interface.launch(share=True)
|
160 |
"""
|
161 |
import gradio as gr
|
162 |
-
import netron
|
163 |
import os
|
164 |
-
import
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
# Start a new Netron server on a dynamic port
|
190 |
-
new_port = 8081 + int(time.time()) % 1000 # Avoid conflicts
|
191 |
-
logging.info(f"Starting Netron on port {new_port}")
|
192 |
-
last_port = new_port
|
193 |
-
last_thread = threading.Thread(target=netron.start, args=(temp_model_path, new_port))
|
194 |
-
last_thread.start()
|
195 |
-
|
196 |
-
# Return iframe with dynamic port
|
197 |
-
iframe_html = f'<iframe src="http://localhost:{new_port}" width="800" height="600"></iframe>'
|
198 |
-
return iframe_html
|
199 |
-
|
200 |
-
except Exception as e:
|
201 |
-
logging.error(f"Error in visualization: {e}")
|
202 |
-
return "An error occurred while visualizing the model."
|
203 |
-
|
204 |
-
# Create Gradio interface
|
205 |
-
interface = gr.Interface(
|
206 |
-
fn=visualize_model,
|
207 |
-
inputs=gr.File(label="Upload Model File"), # Input as a model file
|
208 |
-
outputs=gr.HTML(), # Output the embedded Netron visualization
|
209 |
-
live=True
|
210 |
-
)
|
211 |
-
|
212 |
-
# Launch Gradio server on a fixed port
|
213 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
159 |
interface.launch(share=True)
|
160 |
"""
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|