Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -159,42 +159,39 @@ if __name__ == "__main__":
|
|
159 |
interface.launch(share=True)
|
160 |
"""
|
161 |
|
|
|
162 |
import gradio as gr
|
163 |
import netron
|
164 |
import os
|
165 |
import threading
|
166 |
-
from flask import Flask, send_from_directory
|
167 |
-
|
168 |
-
# Flask app to serve the Netron model visualization
|
169 |
-
app = Flask(__name__)
|
170 |
|
171 |
-
|
172 |
-
# Start a new thread to serve the Netron visualization on a local server
|
173 |
-
netron.start(model_path, port=8080)
|
174 |
-
|
175 |
-
# Define a function to visualize the model and generate an iframe
|
176 |
def visualize_model(model_file):
|
177 |
-
#
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
-
# Start Netron in a separate thread
|
183 |
-
threading.Thread(target=
|
184 |
|
185 |
# Return an iframe embedding the Netron visualization
|
186 |
iframe_html = f'<iframe src="http://localhost:8080" width="800" height="600"></iframe>'
|
187 |
return iframe_html
|
188 |
|
189 |
-
#
|
190 |
interface = gr.Interface(
|
191 |
fn=visualize_model,
|
192 |
-
inputs=gr.File(label="Upload Model File"),
|
193 |
-
outputs=gr.HTML(), # Output is HTML to embed iframe
|
194 |
live=True
|
195 |
)
|
196 |
|
197 |
-
# Start the Gradio interface
|
198 |
interface.launch()
|
199 |
|
200 |
|
|
|
159 |
interface.launch(share=True)
|
160 |
"""
|
161 |
|
162 |
+
|
163 |
import gradio as gr
|
164 |
import netron
|
165 |
import os
|
166 |
import threading
|
|
|
|
|
|
|
|
|
167 |
|
168 |
+
# Define the function to visualize the model
|
|
|
|
|
|
|
|
|
169 |
def visualize_model(model_file):
|
170 |
+
# If the model file is a path (file uploaded), read it
|
171 |
+
if isinstance(model_file, str):
|
172 |
+
model_path = model_file
|
173 |
+
else:
|
174 |
+
# If it's a NamedString (new behavior), save it to a temporary file
|
175 |
+
temp_model_path = f"./temp_model.{model_file.name.split('.')[-1]}"
|
176 |
+
with open(temp_model_path, "wb") as f:
|
177 |
+
f.write(model_file.encode()) # Use encode() to write the string content
|
178 |
+
model_path = temp_model_path
|
179 |
|
180 |
+
# Start Netron visualization in a separate thread
|
181 |
+
threading.Thread(target=netron.start, args=(model_path,)).start()
|
182 |
|
183 |
# Return an iframe embedding the Netron visualization
|
184 |
iframe_html = f'<iframe src="http://localhost:8080" width="800" height="600"></iframe>'
|
185 |
return iframe_html
|
186 |
|
187 |
+
# Create the Gradio interface
|
188 |
interface = gr.Interface(
|
189 |
fn=visualize_model,
|
190 |
+
inputs=gr.File(label="Upload Model File"), # Model file input
|
191 |
+
outputs=gr.HTML(), # Output is HTML to embed the iframe
|
192 |
live=True
|
193 |
)
|
194 |
|
|
|
195 |
interface.launch()
|
196 |
|
197 |
|