Spaces:
Sleeping
Sleeping
fixed exact url
Browse files- api/main.py.backup +33 -13
api/main.py.backup
CHANGED
|
@@ -1,26 +1,46 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
-
Simplified FastAPI server for medical research AI
|
| 4 |
"""
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
-
from typing import Dict, List, Optional, Set
|
| 12 |
-
from pydantic import BaseModel
|
| 13 |
-
import asyncio
|
| 14 |
-
import json
|
| 15 |
import os
|
|
|
|
|
|
|
|
|
|
| 16 |
from datetime import datetime
|
| 17 |
import uuid
|
| 18 |
-
import
|
| 19 |
|
| 20 |
# Configure logging
|
| 21 |
logging.basicConfig(level=logging.INFO)
|
| 22 |
logger = logging.getLogger(__name__)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Import engine - Vercel compatible
|
| 25 |
try:
|
| 26 |
# Try relative import first (Vercel runs from api/ directory)
|
|
@@ -184,7 +204,7 @@ app = FastAPI(
|
|
| 184 |
# CORS middleware
|
| 185 |
app.add_middleware(
|
| 186 |
CORSMiddleware,
|
| 187 |
-
allow_origins=["
|
| 188 |
allow_credentials=True,
|
| 189 |
allow_methods=["*"],
|
| 190 |
allow_headers=["*"],
|
|
|
|
| 1 |
"""
|
| 2 |
+
Medical Research API Server - HuggingFace Compatible Version
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
# ============================================================================
|
| 6 |
+
# IMPORTS AND CONFIGURATION
|
| 7 |
+
# ============================================================================
|
| 8 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import os
|
| 10 |
+
import sys
|
| 11 |
+
import logging # <-- THIS IS MISSING!
|
| 12 |
+
import json
|
| 13 |
from datetime import datetime
|
| 14 |
import uuid
|
| 15 |
+
from typing import Dict, List, Optional, Set
|
| 16 |
|
| 17 |
# Configure logging
|
| 18 |
logging.basicConfig(level=logging.INFO)
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
+
# ============================================================================
|
| 22 |
+
# HUGGINGFACE SPACE CONFIGURATION
|
| 23 |
+
# ============================================================================
|
| 24 |
+
|
| 25 |
+
# Set HuggingFace specific settings
|
| 26 |
+
if os.getenv('SPACE_ID'):
|
| 27 |
+
# We're on HuggingFace Spaces
|
| 28 |
+
print(f"🚀 Running on HuggingFace Space: {os.getenv('SPACE_ID')}")
|
| 29 |
+
# Force port 7860 for HuggingFace
|
| 30 |
+
os.environ['PORT'] = '7860'
|
| 31 |
+
|
| 32 |
+
# Update CORS for HuggingFace
|
| 33 |
+
ALLOWED_ORIGINS = [
|
| 34 |
+
"https://medical-research-ai.vercel.app",
|
| 35 |
+
"http://localhost:3000",
|
| 36 |
+
"https://paulhemb-medsearchpro.hf.space"
|
| 37 |
+
]
|
| 38 |
+
else:
|
| 39 |
+
ALLOWED_ORIGINS = ["*"]
|
| 40 |
+
# Configure logging
|
| 41 |
+
logging.basicConfig(level=logging.INFO)
|
| 42 |
+
logger = logging.getLogger(__name__)
|
| 43 |
+
|
| 44 |
# Import engine - Vercel compatible
|
| 45 |
try:
|
| 46 |
# Try relative import first (Vercel runs from api/ directory)
|
|
|
|
| 204 |
# CORS middleware
|
| 205 |
app.add_middleware(
|
| 206 |
CORSMiddleware,
|
| 207 |
+
allow_origins=["ALLOWED_ORIGINS"],
|
| 208 |
allow_credentials=True,
|
| 209 |
allow_methods=["*"],
|
| 210 |
allow_headers=["*"],
|