richard-su commited on
Commit
0f46e38
·
verified ·
1 Parent(s): 7035546

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -13,13 +13,32 @@ import sys
13
  current_dir = os.path.dirname(os.path.abspath(__file__))
14
  sys.path.insert(0, current_dir)
15
 
16
- # Import the actual app from src
17
- from src.app import create_app, main, get_app
18
 
19
- # Re-export for compatibility
20
- __all__ = ["create_app", "main", "get_app"]
 
 
 
 
 
 
 
 
21
 
22
- # For direct execution
23
- if __name__ == "__main__":
24
- from src.app import run_local
25
- run_local()
 
 
 
 
 
 
 
 
 
 
 
 
13
  current_dir = os.path.dirname(os.path.abspath(__file__))
14
  sys.path.insert(0, current_dir)
15
 
16
+ # Detect environment early
17
+ is_hf_spaces = "SPACE_ID" in os.environ
18
 
19
+ if is_hf_spaces:
20
+ # HF Spaces mode: Set environment and prevent uvicorn from running
21
+ print("🤗 Detected HF Spaces environment")
22
+ os.environ["DEPLOYMENT_MODE"] = "local"
23
+ os.environ["HF_SPACES_MODE"] = "1" # Flag to prevent uvicorn
24
+
25
+ # Import and create app directly
26
+ from src.app import create_app
27
+ app = create_app()
28
+ print("✅ App created for HF Spaces")
29
 
30
+ else:
31
+ # For other environments
32
+ from src.app import create_app, main, get_app
33
+
34
+ # Re-export for compatibility
35
+ __all__ = ["create_app", "main", "get_app", "app"]
36
+
37
+ if __name__ == "__main__":
38
+ # Local development mode: use uvicorn
39
+ print("🏠 Local development mode")
40
+ from src.app import run_local
41
+ run_local()
42
+ else:
43
+ # Other environments
44
+ app = get_app()