ButterM40 commited on
Commit
9633c60
·
1 Parent(s): 67ba315

Test: minimal FastAPI server to verify Spaces build pipeline

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -16
  2. server_minimal.py +72 -0
Dockerfile CHANGED
@@ -6,32 +6,19 @@ WORKDIR /code
6
 
7
  # Set environment variables
8
  ENV PORT=7860
9
- ENV PYTHONPATH=/code
10
- ENV TRANSFORMERS_CACHE=/code/.cache/transformers
11
-
12
- # Install system dependencies
13
- RUN apt-get update && \
14
- apt-get install -y --no-install-recommends \
15
- build-essential \
16
- git \
17
- && rm -rf /var/lib/apt/lists/*
18
 
19
  # Copy requirements first for better caching
20
  COPY requirements.txt .
21
 
22
- # Add torch back to requirements and install everything together
23
  RUN pip install --no-cache-dir --upgrade pip && \
24
- pip install --no-cache-dir torch==2.1.0 transformers==4.46.3 && \
25
- pip install --no-cache-dir -r requirements.txt
26
 
27
  # Copy the rest of the application
28
  COPY . .
29
 
30
- # Create cache directory for transformers
31
- RUN mkdir -p /code/.cache/transformers
32
-
33
  # Make port 7860 available
34
  EXPOSE 7860
35
 
36
  # Run the FastAPI server
37
- CMD ["bash", "-c", "uvicorn server:app --host 0.0.0.0 --port ${PORT} --workers 1"]
 
6
 
7
  # Set environment variables
8
  ENV PORT=7860
 
 
 
 
 
 
 
 
 
9
 
10
  # Copy requirements first for better caching
11
  COPY requirements.txt .
12
 
13
+ # Install only essential packages for now
14
  RUN pip install --no-cache-dir --upgrade pip && \
15
+ pip install --no-cache-dir fastapi uvicorn pydantic python-multipart pillow
 
16
 
17
  # Copy the rest of the application
18
  COPY . .
19
 
 
 
 
20
  # Make port 7860 available
21
  EXPOSE 7860
22
 
23
  # Run the FastAPI server
24
+ CMD ["uvicorn", "server_minimal:app", "--host", "0.0.0.0", "--port", "7860"]
server_minimal.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.staticfiles import StaticFiles
3
+ from fastapi.responses import FileResponse
4
+ from pydantic import BaseModel
5
+ import os
6
+
7
+ # =====================================================
8
+ # FastAPI App Setup
9
+ # =====================================================
10
+ app = FastAPI(title="AI Chat + Summarization + Vision API")
11
+
12
+ # =====================================================
13
+ # API Schemas
14
+ # =====================================================
15
+ class ChatRequest(BaseModel):
16
+ message: str
17
+ max_new_tokens: int = 80
18
+ temperature: float = 0.7
19
+
20
+ class SummaryRequest(BaseModel):
21
+ text: str
22
+ max_length: int = 100
23
+ min_length: int = 25
24
+
25
+ # =====================================================
26
+ # Endpoints (Stubbed for Testing)
27
+ # =====================================================
28
+ @app.post("/api/chat")
29
+ def chat_generate(req: ChatRequest):
30
+ return {
31
+ "success": True,
32
+ "response": f"This is a test response to: {req.message}",
33
+ "tokens": [
34
+ {"token": "This", "alternatives": [{"token": "That", "probability": 0.3}]},
35
+ {"token": " is", "alternatives": [{"token": " was", "probability": 0.2}]},
36
+ {"token": " a", "alternatives": [{"token": " the", "probability": 0.4}]}
37
+ ]
38
+ }
39
+
40
+ @app.post("/api/summarize")
41
+ def summarize_text(req: SummaryRequest):
42
+ return {
43
+ "success": True,
44
+ "summary": f"Summary: {req.text[:100]}..."
45
+ }
46
+
47
+ @app.post("/predict_words")
48
+ def predict_words(req: dict):
49
+ return [
50
+ {"word": "test", "probability": 0.8},
51
+ {"word": "demo", "probability": 0.1},
52
+ {"word": "example", "probability": 0.1}
53
+ ]
54
+
55
+ @app.get("/api/health")
56
+ def health_check():
57
+ return {
58
+ "status": "healthy",
59
+ "models": ["stub-models-for-testing"]
60
+ }
61
+
62
+ # =====================================================
63
+ # Static Files
64
+ # =====================================================
65
+ if os.path.exists("static"):
66
+ app.mount("/static", StaticFiles(directory="static"), name="static")
67
+
68
+ @app.get("/")
69
+ def read_root():
70
+ if os.path.exists("static/index.html"):
71
+ return FileResponse("static/index.html")
72
+ return {"message": "Minimal AI Chat API running!"}