BhumikaMak commited on
Commit
6624545
·
verified ·
1 Parent(s): 2cfd9ce
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -161,20 +161,40 @@ if __name__ == "__main__":
161
 
162
  import gradio as gr
163
  import netron
 
 
 
 
 
 
 
 
 
 
164
 
165
- # Define a function to visualize the model
166
  def visualize_model(model_file):
167
- # Launch the Netron viewer in a web browser
168
- netron.start(model_file)
169
- return "Model visualization launched in browser."
 
170
 
171
- # Create a Gradio interface
 
 
 
 
 
 
 
172
  interface = gr.Interface(
173
  fn=visualize_model,
174
- inputs=gr.File(label="Upload Model File"), # Model file input
175
- outputs="text", # Just a text output to indicate launch
176
  live=True
177
  )
178
 
 
179
  interface.launch()
180
 
 
 
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
+ def start_netron(model_path):
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
+ # Save the model file temporarily
178
+ temp_model_path = os.path.join(os.getcwd(), "weight_files/yolov5.onnx")
179
+ with open(temp_model_path, "wb") as f:
180
+ f.write(model_file.read())
181
 
182
+ # Start Netron in a separate thread
183
+ threading.Thread(target=start_netron, args=(temp_model_path,)).start()
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
+ # Gradio interface to upload the model and show the visualization
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
+