afulara commited on
Commit
2ed7fce
·
1 Parent(s): 480a9c3

Update DOcker file

Browse files
Files changed (2) hide show
  1. Docker +31 -7
  2. backend/main.py +4 -0
Docker CHANGED
@@ -1,13 +1,37 @@
 
1
  FROM python:3.9
2
 
3
- RUN useradd -m -u 1000 user
4
- USER user
5
- ENV PATH="/home/user/.local/bin:$PATH"
6
 
 
7
  WORKDIR /app
8
 
9
- COPY --chown=user ./requirements.txt requirements.txt
10
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
 
11
 
12
- COPY --chown=user . /app
13
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.9 base
2
  FROM python:3.9
3
 
4
+ # Install Node.js & npm (for building React)
5
+ RUN apt-get update && apt-get install -y nodejs npm
 
6
 
7
+ # Create a working directory
8
  WORKDIR /app
9
 
10
+ # Copy requirements and install Python deps
11
+ COPY requirements.txt /app/requirements.txt
12
+ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
13
 
14
+ # Copy the entire project
15
+ COPY . /app
16
+
17
+ # Build the frontend
18
+ WORKDIR /app/frontend
19
+ RUN npm install
20
+ RUN npm run build
21
+
22
+ # Move the built frontend into the backend static folder
23
+ WORKDIR /app
24
+ RUN cp -R /app/frontend/build /app/backend/static
25
+
26
+ # Expose port 7860 (Hugging Face Spaces default)
27
+ EXPOSE 7860
28
+
29
+ # Set environment variables
30
+ ENV PORT 7860
31
+ ENV HOST 0.0.0.0
32
+
33
+ # Switch to the backend directory
34
+ WORKDIR /app/backend
35
+
36
+ # Run the FastAPI application
37
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
backend/main.py CHANGED
@@ -1,6 +1,7 @@
1
  from fastapi import FastAPI, UploadFile, File, HTTPException, WebSocket
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import StreamingResponse
 
4
  from pydantic import BaseModel
5
  from typing import List, Optional, Dict, AsyncGenerator
6
  import os
@@ -25,6 +26,9 @@ load_dotenv()
25
 
26
  app = FastAPI()
27
 
 
 
 
28
  # Configure CORS
29
  app.add_middleware(
30
  CORSMiddleware,
 
1
  from fastapi import FastAPI, UploadFile, File, HTTPException, WebSocket
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import StreamingResponse
4
+ from fastapi.staticfiles import StaticFiles
5
  from pydantic import BaseModel
6
  from typing import List, Optional, Dict, AsyncGenerator
7
  import os
 
26
 
27
  app = FastAPI()
28
 
29
+ # Mount static files
30
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
31
+
32
  # Configure CORS
33
  app.add_middleware(
34
  CORSMiddleware,