Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -145,68 +145,3 @@ with gr.Blocks(css=custom_css) as interface:
|
|
145 |
# Launching Gradio app and handling Netron visualization separately.
|
146 |
if __name__ == "__main__":
|
147 |
interface.launch(share=True)
|
148 |
-
"""
|
149 |
-
|
150 |
-
import gradio as gr
|
151 |
-
import netron
|
152 |
-
import threading
|
153 |
-
import time
|
154 |
-
import tempfile
|
155 |
-
import os
|
156 |
-
|
157 |
-
# Function to start a Netron server and get the file-based URL
|
158 |
-
def start_netron_server(file_path):
|
159 |
-
if not os.path.exists(file_path):
|
160 |
-
return None
|
161 |
-
|
162 |
-
# Temporary directory to store Netron visualizations
|
163 |
-
temp_dir = tempfile.mkdtemp()
|
164 |
-
output_path = os.path.join(temp_dir, "model_view.html")
|
165 |
-
|
166 |
-
# Run Netron in a separate thread with export option
|
167 |
-
def run_netron():
|
168 |
-
netron.start(file_path, browse=False, output=output_path)
|
169 |
-
|
170 |
-
thread = threading.Thread(target=run_netron, daemon=True)
|
171 |
-
thread.start()
|
172 |
-
|
173 |
-
# Wait for Netron to finish initializing
|
174 |
-
time.sleep(2)
|
175 |
-
|
176 |
-
# Ensure the exported file exists
|
177 |
-
if os.path.exists(output_path):
|
178 |
-
return f"file://{output_path}"
|
179 |
-
else:
|
180 |
-
return None
|
181 |
-
|
182 |
-
|
183 |
-
# Gradio function to display the model viewer
|
184 |
-
def visualize_model(file):
|
185 |
-
if file:
|
186 |
-
file_path = file.name
|
187 |
-
#netron_url = start_netron_server(file_path)
|
188 |
-
if True:
|
189 |
-
# Embed the Netron viewer using an iframe with the generated URL
|
190 |
-
iframe_html = f"""
|
191 |
-
# <iframe
|
192 |
-
# src="https://netron.app/?url=https://huggingface.co/FFusion/FFusionXL-BASE/blob/main/vae_encoder/model.onnx"
|
193 |
-
# width="100%"
|
194 |
-
# height="800"
|
195 |
-
# # frameborder="0">
|
196 |
-
# </iframe>
|
197 |
-
"""
|
198 |
-
return iframe_html
|
199 |
-
return "<p>Error: Unable to generate Netron visualization.</p>"
|
200 |
-
return "<p>Please upload a valid model file.</p>"
|
201 |
-
|
202 |
-
|
203 |
-
# Gradio app
|
204 |
-
with gr.Blocks() as demo:
|
205 |
-
gr.Markdown("## Netron Model Viewer with Gradio")
|
206 |
-
file_input = gr.File(label="Upload a Model File (e.g., ONNX, TFLite, etc.)")
|
207 |
-
output_html = gr.HTML(label="Model Visualization")
|
208 |
-
file_input.upload(visualize_model, file_input, output_html)
|
209 |
-
|
210 |
-
# Launch the Gradio app
|
211 |
-
demo.launch()
|
212 |
-
"""
|
|
|
145 |
# Launching Gradio app and handling Netron visualization separately.
|
146 |
if __name__ == "__main__":
|
147 |
interface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|