AhmadYarAI commited on
Commit
d491cd7
·
1 Parent(s): d3722fa

Setup the Hugging face deployment

Browse files
Files changed (2) hide show
  1. Dockerfile +8 -11
  2. main.py +20 -0
Dockerfile CHANGED
@@ -1,24 +1,21 @@
1
- # Use a lightweight Python image
2
  FROM python:3.10-slim
3
 
4
- # 1. Setup User (UID 1000 is mandatory for Hugging Face)
 
 
5
  RUN useradd -m -u 1000 user
6
  USER user
7
  ENV HOME=/home/user \
8
  PATH=/home/user/.local/bin:$PATH
9
 
10
- # 2. Set working directory
11
  WORKDIR $HOME/app
12
 
13
- # 3. Install Requirements
14
- # Copy requirements first to leverage Docker caching
15
  COPY --chown=user:user requirements.txt .
16
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
17
 
18
- # 4. Copy the Application Code
19
- # Note: We copy the 'app' folder into the container
20
- COPY --chown=user:user ./app ./app
21
 
22
- # 5. Startup Command
23
- # We use 'app.main:app' because the code is inside the 'app' folder
24
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
  FROM python:3.10-slim
2
 
3
+ # System dependencies for database/psycopg
4
+ RUN apt-get update && apt-get install -y libpq-dev gcc && rm -rf /var/lib/apt/lists/*
5
+
6
  RUN useradd -m -u 1000 user
7
  USER user
8
  ENV HOME=/home/user \
9
  PATH=/home/user/.local/bin:$PATH
10
 
 
11
  WORKDIR $HOME/app
12
 
13
+ # Copy requirements and install
 
14
  COPY --chown=user:user requirements.txt .
15
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
16
 
17
+ # Copy all files from backend/ into the container
18
+ COPY --chown=user:user . .
 
19
 
20
+ # IMPORTANT: Changed from app.main:app to main:app
21
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
main.py CHANGED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ # Load variables from .env
7
+ load_dotenv()
8
+
9
+ app = FastAPI()
10
+
11
+ app.add_middleware(
12
+ CORSMiddleware,
13
+ allow_origins=["*"],
14
+ allow_methods=["*"],
15
+ allow_headers=["*"],
16
+ )
17
+
18
+ @app.get("/")
19
+ def read_root():
20
+ return {"status": "SmiloCAD API is Live", "db_connected": bool(os.getenv("DATABASE_URL"))}