Spaces:
Sleeping
Sleeping
model saving
Browse files
app.py
CHANGED
@@ -158,19 +158,23 @@ with gr.Blocks(css=custom_css) as interface:
|
|
158 |
if __name__ == "__main__":
|
159 |
interface.launch(share=True)
|
160 |
"""
|
|
|
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 =
|
170 |
with open(file_path, "wb") as f:
|
171 |
-
f.write(model_file.data) #
|
172 |
|
173 |
-
# Start Netron server to
|
174 |
port = 8081
|
175 |
subprocess.Popen(
|
176 |
["netron", "--host", "0.0.0.0", "--port", str(port), file_path],
|
@@ -183,9 +187,6 @@ def visualize_model(model_file):
|
|
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,
|
@@ -195,5 +196,5 @@ demo = gr.Interface(
|
|
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, share=True)
|
|
|
158 |
if __name__ == "__main__":
|
159 |
interface.launch(share=True)
|
160 |
"""
|
161 |
+
|
162 |
import gradio as gr
|
163 |
import os
|
164 |
import subprocess
|
|
|
165 |
|
166 |
# Function to visualize the model
|
167 |
def visualize_model(model_file):
|
168 |
+
# Create the output directory if it doesn't exist
|
169 |
+
output_dir = os.path.join("./models", os.path.dirname(model_file.name))
|
170 |
+
os.makedirs(output_dir, exist_ok=True) # FIXED: Create nested directories if needed
|
171 |
+
|
172 |
# Save the uploaded file
|
173 |
+
file_path = os.path.join("./models", model_file.name)
|
174 |
with open(file_path, "wb") as f:
|
175 |
+
f.write(model_file.data) # Save the uploaded file data
|
176 |
|
177 |
+
# Start Netron server to visualize the model
|
178 |
port = 8081
|
179 |
subprocess.Popen(
|
180 |
["netron", "--host", "0.0.0.0", "--port", str(port), file_path],
|
|
|
187 |
return f"Model uploaded successfully! View it at: {netron_url}"
|
188 |
|
189 |
|
|
|
|
|
|
|
190 |
# Gradio Interface
|
191 |
demo = gr.Interface(
|
192 |
fn=visualize_model,
|
|
|
196 |
description="Upload a model file to visualize its architecture using Netron.",
|
197 |
)
|
198 |
|
199 |
+
# Launch the app
|
200 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|