Spaces:
Sleeping
Sleeping
init space
Browse files- .gitignore +2 -0
- Dockerfile +11 -0
- app.py +23 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# files
|
2 |
+
*.DS_Store
|
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY requirements.txt .
|
6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
7 |
+
|
8 |
+
COPY app.py .
|
9 |
+
|
10 |
+
# Expose port 7860 (Spaces yêu cầu)
|
11 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
|
5 |
+
# Khởi tạo app FastAPI
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
# Load model và tokenizer
|
9 |
+
model_name = "bmd1905/BARTpho2-ViT5-text2text"
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
+
|
13 |
+
# Định nghĩa schema cho request
|
14 |
+
class InputText(BaseModel):
|
15 |
+
text: str
|
16 |
+
|
17 |
+
# Endpoint POST /generate
|
18 |
+
@app.post("/generate")
|
19 |
+
def generate_text(item: InputText):
|
20 |
+
inputs = tokenizer(item.text, return_tensors="pt", truncation=True, max_length=512)
|
21 |
+
outputs = model.generate(**inputs, max_new_tokens=128)
|
22 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
+
return {"answer": response}
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
transformers==4.40.0
|
4 |
+
torch>=1.13.1
|