Second commit for deployment
Browse files- .env +7 -0
- Dockerfile +25 -0
- app/config.py +3 -0
- app/main.py +17 -3
.env
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
DEBUG=False
|
2 |
+
MODEL_PATH=./models/model.pt
|
3 |
+
TEXT_MODEL=bert-base-uncased
|
4 |
+
VISION_MODEL=google/vit-base-patch16-384
|
5 |
+
HF_MODEL_REPO=dixisouls/VQA
|
6 |
+
HF_MODEL_FILENAME=model.pt
|
7 |
+
UPLOAD_DIR=./uploads
|
Dockerfile
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
# Copy requirements first for better caching
|
6 |
+
COPY requirements.txt .
|
7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
8 |
+
|
9 |
+
# Copy the rest of the application
|
10 |
+
COPY app/ ./app/
|
11 |
+
COPY models/ ./models/
|
12 |
+
COPY .env .
|
13 |
+
|
14 |
+
# Create required directories
|
15 |
+
RUN mkdir -p uploads models
|
16 |
+
|
17 |
+
# Set environment variables
|
18 |
+
ENV PYTHONPATH=/app
|
19 |
+
ENV PORT=7860
|
20 |
+
|
21 |
+
# Expose the port
|
22 |
+
EXPOSE 7860
|
23 |
+
|
24 |
+
# Start the application
|
25 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app/config.py
CHANGED
@@ -35,6 +35,9 @@ class Settings(BaseSettings):
|
|
35 |
# CORS settings
|
36 |
ALLOW_ORIGINS: list[str] = ["*"]
|
37 |
|
|
|
|
|
|
|
38 |
class Config:
|
39 |
env_file = ".env"
|
40 |
case_sensitive = True
|
|
|
35 |
# CORS settings
|
36 |
ALLOW_ORIGINS: list[str] = ["*"]
|
37 |
|
38 |
+
# Hugging Face Spaces specific settings
|
39 |
+
PORT: int = int(os.getenv("PORT", "7860"))
|
40 |
+
|
41 |
class Config:
|
42 |
env_file = ".env"
|
43 |
case_sensitive = True
|
app/main.py
CHANGED
@@ -10,6 +10,7 @@ from contextlib import asynccontextmanager
|
|
10 |
|
11 |
from app.routers import vqa
|
12 |
from app.services.model_service import ModelService
|
|
|
13 |
|
14 |
# Configure logging
|
15 |
logging.basicConfig(
|
@@ -38,10 +39,10 @@ app = FastAPI(
|
|
38 |
lifespan=lifespan
|
39 |
)
|
40 |
|
41 |
-
# Add CORS middleware
|
42 |
app.add_middleware(
|
43 |
CORSMiddleware,
|
44 |
-
allow_origins=["*"], # Allow all origins
|
45 |
allow_credentials=True,
|
46 |
allow_methods=["*"],
|
47 |
allow_headers=["*"],
|
@@ -63,6 +64,19 @@ async def health_check():
|
|
63 |
raise HTTPException(status_code=503, detail="Model not loaded")
|
64 |
return {"status": "healthy", "model_loaded": True}
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
if __name__ == "__main__":
|
67 |
import uvicorn
|
68 |
-
|
|
|
|
10 |
|
11 |
from app.routers import vqa
|
12 |
from app.services.model_service import ModelService
|
13 |
+
from app.config import settings
|
14 |
|
15 |
# Configure logging
|
16 |
logging.basicConfig(
|
|
|
39 |
lifespan=lifespan
|
40 |
)
|
41 |
|
42 |
+
# Add CORS middleware with more permissive settings for Hugging Face Spaces
|
43 |
app.add_middleware(
|
44 |
CORSMiddleware,
|
45 |
+
allow_origins=["*"], # Allow all origins
|
46 |
allow_credentials=True,
|
47 |
allow_methods=["*"],
|
48 |
allow_headers=["*"],
|
|
|
64 |
raise HTTPException(status_code=503, detail="Model not loaded")
|
65 |
return {"status": "healthy", "model_loaded": True}
|
66 |
|
67 |
+
# Root endpoint for Hugging Face Spaces
|
68 |
+
@app.get("/")
|
69 |
+
async def root():
|
70 |
+
"""Root endpoint returning basic info about the API"""
|
71 |
+
return {
|
72 |
+
"name": "VizWiz Visual Question Answering API",
|
73 |
+
"description": "API for visual question answering on images",
|
74 |
+
"documentation": "/docs",
|
75 |
+
"health_check": "/health",
|
76 |
+
"version": "1.0.0"
|
77 |
+
}
|
78 |
+
|
79 |
if __name__ == "__main__":
|
80 |
import uvicorn
|
81 |
+
port = settings.PORT
|
82 |
+
uvicorn.run("app.main:app", host="0.0.0.0", port=port, reload=False)
|