Ananthakr1shnan commited on
Commit
f48599d
·
1 Parent(s): b43b496

Updated files

Browse files
Files changed (1) hide show
  1. app.py +8 -44
app.py CHANGED
@@ -9,6 +9,9 @@ from datetime import datetime
9
  from pathlib import Path
10
  from contextlib import asynccontextmanager
11
 
 
 
 
12
  # Set up environment variables for Hugging Face Spaces compatibility
13
  def setup_environment():
14
  env_vars = {
@@ -87,46 +90,6 @@ from src.components.auth import AuthManager
87
  auth_manager = AuthManager()
88
  security = HTTPBearer(auto_error=False)
89
 
90
- # Simple settings for development
91
-
92
- # Settings for Hugging Face Spaces: use /tmp dirs
93
- class Settings:
94
- def __init__(self):
95
- # Detect if running in Hugging Face Spaces (PORT is set and not a typical local port)
96
- port_env = os.environ.get('PORT')
97
- self.is_spaces = port_env is not None and port_env not in ['8000', '5000', '8080']
98
- self.server = type('ServerSettings', (), {
99
- 'debug': not self.is_spaces,
100
- 'host': '0.0.0.0',
101
- 'port': int(port_env) if port_env else 8000 # Default to 8000 for local
102
- })()
103
- self.security = type('SecuritySettings', (), {
104
- 'cors_origins': ["*"],
105
- 'cors_methods': ["*"],
106
- 'cors_headers': ["*"]
107
- })()
108
-
109
- def get_static_dir(self):
110
- if self.is_spaces:
111
- return "/tmp/researchmate/static"
112
- return "src/static"
113
-
114
- def get_templates_dir(self):
115
- # Templates can remain in src for both
116
- return "src/templates"
117
-
118
- def get_upload_dir(self):
119
- if self.is_spaces:
120
- return "/tmp/researchmate/uploads"
121
- return "uploads"
122
-
123
- def get_logs_dir(self):
124
- if self.is_spaces:
125
- return "/tmp/researchmate/logs"
126
- return "logs"
127
-
128
- settings = Settings()
129
-
130
  # Initialize ResearchMate and Citation Analyzer (will be done during loading screen)
131
  research_mate = None
132
  citation_analyzer = None
@@ -288,6 +251,7 @@ app.add_middleware(
288
  allow_headers=settings.security.cors_headers,
289
  )
290
 
 
291
  # Mount static files with cache control for development
292
  static_dir = Path(settings.get_static_dir())
293
  static_dir.mkdir(parents=True, exist_ok=True)
@@ -786,13 +750,13 @@ async def startup_event():
786
  # Local development: run with `python app.py`
787
  if __name__ == "__main__":
788
  import uvicorn
789
- port = settings.server.port
790
- host = settings.server.host
791
  print(f"\nStarting ResearchMate locally at http://{host}:{port}\n")
792
  uvicorn.run(
793
  "app:app",
794
  host=host,
795
  port=port,
796
- log_level="info",
797
- reload=True
798
  )
 
9
  from pathlib import Path
10
  from contextlib import asynccontextmanager
11
 
12
+ # Import centralized settings
13
+ from src.settings import settings
14
+
15
  # Set up environment variables for Hugging Face Spaces compatibility
16
  def setup_environment():
17
  env_vars = {
 
90
  auth_manager = AuthManager()
91
  security = HTTPBearer(auto_error=False)
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  # Initialize ResearchMate and Citation Analyzer (will be done during loading screen)
94
  research_mate = None
95
  citation_analyzer = None
 
251
  allow_headers=settings.security.cors_headers,
252
  )
253
 
254
+
255
  # Mount static files with cache control for development
256
  static_dir = Path(settings.get_static_dir())
257
  static_dir.mkdir(parents=True, exist_ok=True)
 
750
  # Local development: run with `python app.py`
751
  if __name__ == "__main__":
752
  import uvicorn
753
+ port = settings.server.port or 7860
754
+ host = settings.server.host or "0.0.0.0"
755
  print(f"\nStarting ResearchMate locally at http://{host}:{port}\n")
756
  uvicorn.run(
757
  "app:app",
758
  host=host,
759
  port=port,
760
+ log_level=settings.server.log_level,
761
+ reload=settings.server.reload
762
  )