fix: declare ZeroGPU capability and launch Space
#3
by thangvip - opened
app.py
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
|
|
| 1 |
import sys
|
| 2 |
from pathlib import Path
|
| 3 |
|
| 4 |
sys.path.insert(0, str(Path(__file__).resolve().parent / "src"))
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from compliment_forest.server import create_app
|
| 7 |
|
| 8 |
-
app = create_app()
|
| 9 |
-
demo = app
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import sys
|
| 3 |
from pathlib import Path
|
| 4 |
|
| 5 |
sys.path.insert(0, str(Path(__file__).resolve().parent / "src"))
|
| 6 |
|
| 7 |
+
try:
|
| 8 |
+
import spaces
|
| 9 |
+
except ImportError:
|
| 10 |
+
class _Spaces:
|
| 11 |
+
@staticmethod
|
| 12 |
+
def GPU(*_args, **_kwargs):
|
| 13 |
+
return lambda function: function
|
| 14 |
+
|
| 15 |
+
spaces = _Spaces()
|
| 16 |
+
|
| 17 |
from compliment_forest.server import create_app
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
@spaces.GPU(duration=1)
|
| 21 |
+
def zerogpu_capability_probe() -> bool:
|
| 22 |
+
"""Declare ZeroGPU compatibility without spending quota in demo mode."""
|
| 23 |
+
return True
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
app = create_app()
|
| 27 |
|
| 28 |
+
if os.getenv("SPACE_ID"):
|
| 29 |
+
app.launch(show_error=True)
|
| 30 |
+
elif __name__ == "__main__":
|
| 31 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|