Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	initial netron template
Browse files
    	
        app.py
    CHANGED
    
    | @@ -158,46 +158,22 @@ with gr.Blocks(css=custom_css) as interface: | |
| 158 | 
             
            if __name__ == "__main__":
         | 
| 159 | 
             
                interface.launch(share=True)
         | 
| 160 | 
             
            """
         | 
| 161 | 
            -
            import gradio as gr
         | 
| 162 | 
            -
            import os
         | 
| 163 | 
            -
            import subprocess
         | 
| 164 | 
            -
             | 
| 165 | 
            -
            # Function to visualize the model
         | 
| 166 | 
            -
            def visualize_model(model_file):
         | 
| 167 | 
            -
                # Create the output directory if it doesn't exist
         | 
| 168 | 
            -
                output_dir = "./models/tmp/gradio/"
         | 
| 169 | 
            -
                os.makedirs(output_dir, exist_ok=True)  # Create directories if needed
         | 
| 170 | 
            -
             | 
| 171 | 
            -
                # Define the file path to save
         | 
| 172 | 
            -
                file_path = os.path.join(output_dir, model_file.name)
         | 
| 173 | 
            -
             | 
| 174 | 
            -
                # Save the uploaded file
         | 
| 175 | 
            -
                with open(file_path, "wb") as f:
         | 
| 176 | 
            -
                    with open(model_file.name, "rb") as uploaded_file:
         | 
| 177 | 
            -
                        f.write(uploaded_file.read())  # FIXED: Properly read and write file data
         | 
| 178 | 
            -
             | 
| 179 | 
            -
                # Start Netron server to visualize the model
         | 
| 180 | 
            -
                port = 8081
         | 
| 181 | 
            -
                subprocess.Popen(
         | 
| 182 | 
            -
                    ["netron", "--host", "0.0.0.0", "--port", str(port), file_path],
         | 
| 183 | 
            -
                    stdout=subprocess.PIPE,
         | 
| 184 | 
            -
                    stderr=subprocess.PIPE,
         | 
| 185 | 
            -
                )
         | 
| 186 |  | 
| 187 | 
            -
             | 
| 188 | 
            -
             | 
| 189 | 
            -
                return f"Model uploaded successfully! View it at: {netron_url}"
         | 
| 190 |  | 
|  | |
|  | |
|  | |
| 191 |  | 
| 192 | 
            -
            # Gradio  | 
| 193 | 
            -
             | 
| 194 | 
             
                fn=visualize_model,
         | 
| 195 | 
            -
                inputs= | 
| 196 | 
            -
                outputs= | 
| 197 | 
            -
                title="Model  | 
| 198 | 
            -
                description=" | 
| 199 | 
             
            )
         | 
| 200 |  | 
| 201 | 
             
            # Launch the app
         | 
| 202 | 
            -
             | 
| 203 | 
            -
             | 
|  | |
| 158 | 
             
            if __name__ == "__main__":
         | 
| 159 | 
             
                interface.launch(share=True)
         | 
| 160 | 
             
            """
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 161 |  | 
| 162 | 
            +
            import gradio as gr
         | 
| 163 | 
            +
            import netron
         | 
|  | |
| 164 |  | 
| 165 | 
            +
            # Function to visualize the model using Netron
         | 
| 166 | 
            +
            def visualize_model(model_path):
         | 
| 167 | 
            +
                netron.start(model_path)
         | 
| 168 |  | 
| 169 | 
            +
            # Create Gradio interface
         | 
| 170 | 
            +
            iface = gr.Interface(
         | 
| 171 | 
             
                fn=visualize_model,
         | 
| 172 | 
            +
                inputs="text",
         | 
| 173 | 
            +
                outputs="text",
         | 
| 174 | 
            +
                title="Model Visualization with Netron",
         | 
| 175 | 
            +
                description="Enter the path to your model file (e.g., .onnx, .h5) to visualize."
         | 
| 176 | 
             
            )
         | 
| 177 |  | 
| 178 | 
             
            # Launch the app
         | 
| 179 | 
            +
            iface.launch(share=True)
         | 
|  |