Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -164,28 +164,36 @@ import os
|
|
164 |
import threading
|
165 |
import time
|
166 |
|
167 |
-
# Function to start Netron server
|
168 |
-
def start_netron_server(model_file
|
169 |
if not os.path.exists(model_file):
|
170 |
return "Error: Model file does not exist."
|
171 |
|
172 |
# Start Netron in a thread
|
173 |
-
|
|
|
|
|
|
|
174 |
thread.start()
|
175 |
|
176 |
-
# Wait for the server to
|
177 |
time.sleep(2)
|
|
|
|
|
|
|
|
|
178 |
|
179 |
-
#
|
180 |
def visualize_model(file):
|
181 |
if file:
|
182 |
file_path = file.name
|
183 |
-
port =
|
184 |
-
start_netron_server(file_path, port)
|
185 |
|
|
|
|
|
186 |
iframe_url = f"https://bhumikamak-neuralvista.hf.space:{port}/"
|
187 |
|
188 |
-
# Embed the
|
189 |
iframe_html = f"""
|
190 |
<iframe
|
191 |
src="{iframe_url}"
|
|
|
164 |
import threading
|
165 |
import time
|
166 |
|
167 |
+
# Function to start Netron server and get its port
|
168 |
+
def start_netron_server(model_file):
|
169 |
if not os.path.exists(model_file):
|
170 |
return "Error: Model file does not exist."
|
171 |
|
172 |
# Start Netron in a thread
|
173 |
+
def run_netron():
|
174 |
+
netron.start(model_file, browse=False) # Prevent opening in a local browser
|
175 |
+
|
176 |
+
thread = threading.Thread(target=run_netron, daemon=True)
|
177 |
thread.start()
|
178 |
|
179 |
+
# Wait for the server to start
|
180 |
time.sleep(2)
|
181 |
+
|
182 |
+
# Netron typically uses port 8080 by default, but you may need to confirm this dynamically
|
183 |
+
port = 8080
|
184 |
+
return port
|
185 |
|
186 |
+
# Gradio function to visualize the model
|
187 |
def visualize_model(file):
|
188 |
if file:
|
189 |
file_path = file.name
|
190 |
+
port = start_netron_server(file_path)
|
|
|
191 |
|
192 |
+
# Construct the iframe URL using Hugging Face's public domain
|
193 |
+
space_url = os.getenv("SPACE_ID", "your-space-id") # Replace 'your-space-id' with actual ID if testing locally
|
194 |
iframe_url = f"https://bhumikamak-neuralvista.hf.space:{port}/"
|
195 |
|
196 |
+
# Embed the iframe into the Gradio app
|
197 |
iframe_html = f"""
|
198 |
<iframe
|
199 |
src="{iframe_url}"
|