| import os | |
| import sys | |
| from pathlib import Path | |
| # Ensure 'src' directory is importable so we can reuse the existing Gradio app | |
| ROOT = Path(__file__).resolve().parent | |
| SRC = ROOT / "src" | |
| if str(SRC) not in sys.path: | |
| sys.path.insert(0, str(SRC)) | |
| # Configure backend API base URL for Spaces if not set | |
| os.environ.setdefault("API_BASE_URL", "http://129.212.240.44:80") | |
| # Import the existing Gradio Blocks demo from src/sharp/web/app.py | |
| from sharp.web.app import demo as _demo # type: ignore | |
| # Expose both names for Hugging Face Spaces compatibility | |
| demo = _demo | |
| app = _demo | |
| if __name__ == "__main__": | |
| # On Spaces, the platform handles networking; this is for local testing | |
| port_env = os.getenv("PORT", "7860") | |
| try: | |
| port = int(port_env) | |
| except ValueError: | |
| port = 7860 | |
| demo.launch(server_name="0.0.0.0", server_port=port) | |