Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from PIL import Image
|
|
@@ -44,13 +45,13 @@ def process_image(sample_choice, uploaded_image, yolo_versions):
|
|
| 44 |
|
| 45 |
# Custom CSS for styling (optional)
|
| 46 |
custom_css = """
|
| 47 |
-
run_button {
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
border-radius: 5px;
|
| 52 |
-
font-size: 14px;
|
| 53 |
-
}
|
| 54 |
"""
|
| 55 |
|
| 56 |
# Gradio UI
|
|
@@ -113,3 +114,67 @@ with gr.Blocks(css=custom_css) as interface:
|
|
| 113 |
# Launch Gradio app
|
| 114 |
if __name__ == "__main__":
|
| 115 |
interface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
from PIL import Image
|
|
|
|
| 45 |
|
| 46 |
# Custom CSS for styling (optional)
|
| 47 |
custom_css = """
|
| 48 |
+
#run_button {
|
| 49 |
+
# background-color: purple;
|
| 50 |
+
# color: white;
|
| 51 |
+
# width: 120px;
|
| 52 |
+
#border-radius: 5px;
|
| 53 |
+
#font-size: 14px;
|
| 54 |
+
#}
|
| 55 |
"""
|
| 56 |
|
| 57 |
# Gradio UI
|
|
|
|
| 114 |
# Launch Gradio app
|
| 115 |
if __name__ == "__main__":
|
| 116 |
interface.launch(share=True)
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
import gradio as gr
|
| 120 |
+
import netron
|
| 121 |
+
import threading
|
| 122 |
+
import time
|
| 123 |
+
import tempfile
|
| 124 |
+
import os
|
| 125 |
+
|
| 126 |
+
# Function to start a Netron server and get the file-based URL
|
| 127 |
+
def start_netron_server(file_path):
|
| 128 |
+
if not os.path.exists(file_path):
|
| 129 |
+
return None
|
| 130 |
+
|
| 131 |
+
# Temporary directory to store Netron visualizations
|
| 132 |
+
temp_dir = tempfile.mkdtemp()
|
| 133 |
+
output_path = os.path.join(temp_dir, "model_view.html")
|
| 134 |
+
|
| 135 |
+
# Run Netron in a separate thread with export option
|
| 136 |
+
def run_netron():
|
| 137 |
+
netron.start(file_path, browse=False, output=output_path)
|
| 138 |
+
|
| 139 |
+
thread = threading.Thread(target=run_netron, daemon=True)
|
| 140 |
+
thread.start()
|
| 141 |
+
|
| 142 |
+
# Wait for Netron to finish initializing
|
| 143 |
+
time.sleep(2)
|
| 144 |
+
|
| 145 |
+
# Ensure the exported file exists
|
| 146 |
+
if os.path.exists(output_path):
|
| 147 |
+
return f"file://{output_path}"
|
| 148 |
+
else:
|
| 149 |
+
return None
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# Gradio function to display the model viewer
|
| 153 |
+
def visualize_model(file):
|
| 154 |
+
if file:
|
| 155 |
+
file_path = file.name
|
| 156 |
+
netron_url = start_netron_server(file_path)
|
| 157 |
+
if netron_url:
|
| 158 |
+
# Embed the Netron viewer using an iframe with the generated URL
|
| 159 |
+
iframe_html = f"""
|
| 160 |
+
<iframe
|
| 161 |
+
src="https://netron.app/?url=https://huggingface.co/FFusion/FFusionXL-BASE/blob/main/vae_encoder/model.onnx"
|
| 162 |
+
width="100%"
|
| 163 |
+
height="800"
|
| 164 |
+
frameborder="0">
|
| 165 |
+
</iframe>
|
| 166 |
+
"""
|
| 167 |
+
return iframe_html
|
| 168 |
+
return "<p>Error: Unable to generate Netron visualization.</p>"
|
| 169 |
+
return "<p>Please upload a valid model file.</p>"
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
# Gradio app
|
| 173 |
+
with gr.Blocks() as demo:
|
| 174 |
+
gr.Markdown("## Netron Model Viewer with Gradio")
|
| 175 |
+
file_input = gr.File(label="Upload a Model File (e.g., ONNX, TFLite, etc.)")
|
| 176 |
+
output_html = gr.HTML(label="Model Visualization")
|
| 177 |
+
file_input.upload(visualize_model, file_input, output_html)
|
| 178 |
+
|
| 179 |
+
# Launch the Gradio app
|
| 180 |
+
demo.launch()
|