Bagi4 commited on
Commit
502401a
1 Parent(s): 530b8fc

upload project

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -0
  2. main.py +38 -0
  3. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ COPY . .
4
+
5
+ RUN pip install --upgrade -r requirements.txt
6
+
7
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ from transformers import pipeline
5
+
6
+ logging.basicConfig(
7
+ format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
8
+ level=logging.DEBUG,
9
+ datefmt='%Y-%m-%d %H:%M:%S'
10
+ )
11
+ classifier = pipeline("zero-shot-classification", model="models/classificator", use_fast=True)
12
+ app = FastAPI()
13
+
14
+
15
+ class RequestData(BaseModel):
16
+ multiLabel: bool
17
+ sequence: str
18
+ labels: list[str]
19
+
20
+
21
+ class ResponseData(BaseModel):
22
+ sequence: str
23
+ labels: list[str]
24
+ scores: list[float]
25
+
26
+
27
+ @app.post("/classify", response_model=ResponseData, tags=["Classificator"])
28
+ async def classify_text(data: RequestData):
29
+ result = classifier(data.sequence, data.labels, multi_label=data.multiLabel)
30
+ logging.info(result)
31
+
32
+ return result
33
+
34
+
35
+ @app.get("/ping", tags=["TEST"])
36
+ def ping():
37
+ return "pong"
38
+
requirements.txt ADDED
Binary file (2.55 kB). View file