Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -160,23 +160,40 @@ if __name__ == "__main__":
|
|
160 |
"""
|
161 |
import gradio as gr
|
162 |
import netron
|
|
|
|
|
163 |
|
164 |
-
# Function to
|
165 |
-
def
|
166 |
-
# Start Netron
|
167 |
-
netron.start(model_path
|
168 |
-
|
169 |
-
#
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
# Create Gradio interface
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
160 |
"""
|
161 |
import gradio as gr
|
162 |
import netron
|
163 |
+
import os
|
164 |
+
import threading
|
165 |
|
166 |
+
# Function to launch Netron in a separate thread
|
167 |
+
def launch_netron(model_path):
|
168 |
+
# Start Netron server for the model file
|
169 |
+
netron.start(model_path)
|
170 |
+
|
171 |
+
# Function to handle file upload and launch Netron
|
172 |
+
def visualize_model(model_file):
|
173 |
+
# Save the uploaded model file temporarily
|
174 |
+
model_path = os.path.join("temp_models", model_file.name)
|
175 |
+
os.makedirs("temp_models", exist_ok=True)
|
176 |
+
|
177 |
+
with open(model_path, "wb") as f:
|
178 |
+
f.write(model_file.read())
|
179 |
+
|
180 |
+
# Launch Netron in a separate thread
|
181 |
+
threading.Thread(target=launch_netron, args=(model_path,), daemon=True).start()
|
182 |
+
|
183 |
+
return f"Netron is running for {model_file.name}. Open your browser at http://localhost:8080."
|
184 |
|
185 |
# Create Gradio interface
|
186 |
+
with gr.Blocks() as interface:
|
187 |
+
gr.Markdown("<h1 style='color: lightgrey;'>Model Visualization with Netron</h1>")
|
188 |
+
gr.Markdown("<p style='color: lightgrey;'>Upload your model file (e.g., .onnx, .pb) to visualize it.</p>")
|
189 |
+
|
190 |
+
model_input = gr.File(label="Upload Model File", type="file")
|
191 |
+
output_text = gr.Textbox(label="Output", interactive=False)
|
192 |
+
|
193 |
+
run_button = gr.Button("Visualize Model")
|
194 |
+
|
195 |
+
run_button.click(fn=visualize_model, inputs=model_input, outputs=output_text)
|
196 |
+
|
197 |
+
# Launch Gradio app
|
198 |
+
interface.launch(share=True)
|
199 |
+
|