add app.py for hf space
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
# Ensure 'src' directory is importable so we can reuse the existing Gradio app
|
| 6 |
+
ROOT = Path(__file__).resolve().parent
|
| 7 |
+
SRC = ROOT / "src"
|
| 8 |
+
if str(SRC) not in sys.path:
|
| 9 |
+
sys.path.insert(0, str(SRC))
|
| 10 |
+
|
| 11 |
+
# Import the existing Gradio Blocks demo from src/sharp/web/app.py
|
| 12 |
+
from sharp.web.app import demo as _demo # type: ignore
|
| 13 |
+
|
| 14 |
+
# Expose both names for Hugging Face Spaces compatibility
|
| 15 |
+
demo = _demo
|
| 16 |
+
app = _demo
|
| 17 |
+
|
| 18 |
+
if __name__ == "__main__":
|
| 19 |
+
# On Spaces, the platform handles networking; this is for local testing
|
| 20 |
+
port_env = os.getenv("PORT", "7860")
|
| 21 |
+
try:
|
| 22 |
+
port = int(port_env)
|
| 23 |
+
except ValueError:
|
| 24 |
+
port = 7860
|
| 25 |
+
demo.launch(server_name="0.0.0.0", server_port=port)
|