Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +11 -0
- app.py +50 -0
- requirements.txt +4 -0
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
MODEL_NAME = "mjpsm/progress-generation-model"
|
| 9 |
+
|
| 10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 13 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to(device)
|
| 14 |
+
|
| 15 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 16 |
+
|
| 17 |
+
class Request(BaseModel):
|
| 18 |
+
text: str
|
| 19 |
+
|
| 20 |
+
def generate_response(user_input):
|
| 21 |
+
prompt = f"""<|system|>
|
| 22 |
+
You describe what progress was achieved in one sentence.
|
| 23 |
+
<|user|>
|
| 24 |
+
{user_input}
|
| 25 |
+
<|assistant|>
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 29 |
+
|
| 30 |
+
with torch.no_grad():
|
| 31 |
+
outputs = model.generate(
|
| 32 |
+
**inputs,
|
| 33 |
+
max_new_tokens=50,
|
| 34 |
+
temperature=0.6,
|
| 35 |
+
top_p=0.9,
|
| 36 |
+
repetition_penalty=1.2,
|
| 37 |
+
pad_token_id=tokenizer.eos_token_id
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 41 |
+
return decoded.split("<|assistant|>")[-1].strip()
|
| 42 |
+
|
| 43 |
+
@app.get("/")
|
| 44 |
+
def root():
|
| 45 |
+
return {"message": "Progress Model API running"}
|
| 46 |
+
|
| 47 |
+
@app.post("/predict")
|
| 48 |
+
def predict(req: Request):
|
| 49 |
+
result = generate_response(req.text)
|
| 50 |
+
return {"output": result}
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
transformers
|
| 4 |
+
torch
|