Spaces:
Runtime error
Runtime error
| ```python | |
| import gradio as gr | |
| import logging | |
| # Existing imports and code (omitted for brevity) remain unchanged until the launch section | |
| if __name__ == "__main__": | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| try: | |
| logger.info("Starting Gradio application on http://127.0.0.1:7860") | |
| demo.launch( | |
| share=False, | |
| server_name="127.0.0.1", | |
| server_port=7860, | |
| debug=True # Enable debug mode for detailed error output | |
| ) | |
| except Exception as e: | |
| logger.error(f"Gradio launch failed: {str(e)}") | |
| logger.info("Trying alternative port 7861...") | |
| try: | |
| demo.launch( | |
| share=False, | |
| server_name="127.0.0.1", | |
| server_port=7861, | |
| debug=True | |
| ) | |
| except Exception as e2: | |
| logger.error(f"Gradio launch failed on port 7861: {str(e2)}") | |
| raise | |
| ``` | |
| **Changes**: | |
| - Added explicit `server_name="127.0.0.1"` for local binding. | |
| - Enabled `debug=True` for detailed Gradio logs. | |
| - Added a fallback to try port 7861 if 7860 fails. | |
| - Enhanced logging with `logging` module to capture initialization errors. | |