Add application file
Browse files- Dockerfile +13 -0
- main.py +18 -0
- models.py +5 -0
- requirements.txt +4 -0
Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
EXPOSE 7860
|
| 12 |
+
|
| 13 |
+
CMD ["python", "main.py"]
|
main.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Depends, Request
|
| 2 |
+
import models
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import uvicorn
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
@app.get('/detect_lang')
|
| 10 |
+
async def detect_lang(text: models.Text):
|
| 11 |
+
try:
|
| 12 |
+
pipe(text.text)
|
| 13 |
+
except Exception as e:
|
| 14 |
+
raise HTTPException(status_code=400, detail=f'{e}')
|
| 15 |
+
|
| 16 |
+
if __name__ == "__main__":
|
| 17 |
+
pipe = pipeline("text-classification", model="rifkat/uz_kr_lang-detection")
|
| 18 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
models.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Text(BaseModel):
|
| 5 |
+
text: str
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.81.0
|
| 2 |
+
uvicorn==0.18.3
|
| 3 |
+
pydantic==1.9.2
|
| 4 |
+
transformers
|