Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +18 -0
- app.py +24 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 1. Base image with Python
|
2 |
+
FROM python:3.13-slim
|
3 |
+
|
4 |
+
# 2. Set working dir
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# 3. Copy and install dependencies
|
8 |
+
COPY requirements.txt .
|
9 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
10 |
+
|
11 |
+
# 4. Copy the FastAPI app
|
12 |
+
COPY app.py .
|
13 |
+
|
14 |
+
# 5. Expose port (choose 80 or any you like)
|
15 |
+
EXPOSE 80
|
16 |
+
|
17 |
+
# 6. Launch with Uvicorn
|
18 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"]
|
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
app = FastAPI(title="SAM_MedTesting")
|
6 |
+
|
7 |
+
# Load your model once at startup
|
8 |
+
generator = pipeline("text-generation", model="gpt2")
|
9 |
+
|
10 |
+
class GenerationRequest(BaseModel):
|
11 |
+
prompt: str
|
12 |
+
max_new_tokens: int = 50
|
13 |
+
|
14 |
+
class GenerationResponse(BaseModel):
|
15 |
+
generated_text: str
|
16 |
+
|
17 |
+
@app.post("/generate", response_model=GenerationResponse)
|
18 |
+
def generate(req: GenerationRequest):
|
19 |
+
out = generator(req.prompt, max_length=req.max_new_tokens, do_sample=True)
|
20 |
+
return GenerationResponse(generated_text=out[0]["generated_text"])
|
21 |
+
|
22 |
+
@app.get("/health")
|
23 |
+
def health():
|
24 |
+
return {"status": "ok"}
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn[standard]
|
3 |
+
transformers
|
4 |
+
torch
|