Spaces:
Sleeping
Sleeping
fastapi init
Browse files- .gitignore +2 -0
- main.py +23 -0
- requirements.txt +58 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
venv
|
2 |
+
__pycache__
|
main.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from transformers import pipeline
|
3 |
+
from pydantic import BaseModel
|
4 |
+
|
5 |
+
class TextQuery(BaseModel):
|
6 |
+
text: str
|
7 |
+
|
8 |
+
|
9 |
+
def predict(text: str):
|
10 |
+
model_name = "blanchefort/rubert-base-cased-sentiment-rurewiews"
|
11 |
+
pipe = pipeline("text-classification", model=model_name, return_all_scores=True)
|
12 |
+
scores = pipe(text)[0]
|
13 |
+
sorted_scores = sorted(scores, key=lambda x: x['score'], reverse=True)
|
14 |
+
return sorted_scores
|
15 |
+
|
16 |
+
|
17 |
+
app = FastAPI()
|
18 |
+
|
19 |
+
@app.post("/", )
|
20 |
+
def home(request: Request, q: TextQuery):
|
21 |
+
|
22 |
+
|
23 |
+
return predict(q.text)
|
requirements.txt
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py==2.1.0
|
2 |
+
annotated-types==0.6.0
|
3 |
+
anyio==4.3.0
|
4 |
+
astunparse==1.6.3
|
5 |
+
cachetools==5.3.3
|
6 |
+
certifi==2024.2.2
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
fastapi==0.110.0
|
10 |
+
filelock==3.13.1
|
11 |
+
flatbuffers==23.5.26
|
12 |
+
fsspec==2024.2.0
|
13 |
+
gast==0.5.4
|
14 |
+
google-auth==2.28.1
|
15 |
+
google-auth-oauthlib==1.2.0
|
16 |
+
google-pasta==0.2.0
|
17 |
+
grpcio==1.62.0
|
18 |
+
h11==0.14.0
|
19 |
+
h5py==3.10.0
|
20 |
+
huggingface-hub==0.21.2
|
21 |
+
idna==3.6
|
22 |
+
keras==2.15.0
|
23 |
+
libclang==16.0.6
|
24 |
+
Markdown==3.5.2
|
25 |
+
MarkupSafe==2.1.5
|
26 |
+
ml-dtypes==0.2.0
|
27 |
+
numpy==1.26.4
|
28 |
+
oauthlib==3.2.2
|
29 |
+
opt-einsum==3.3.0
|
30 |
+
packaging==23.2
|
31 |
+
protobuf==4.25.3
|
32 |
+
pyasn1==0.5.1
|
33 |
+
pyasn1-modules==0.3.0
|
34 |
+
pydantic==2.6.3
|
35 |
+
pydantic_core==2.16.3
|
36 |
+
PyYAML==6.0.1
|
37 |
+
regex==2023.12.25
|
38 |
+
requests==2.31.0
|
39 |
+
requests-oauthlib==1.3.1
|
40 |
+
rsa==4.9
|
41 |
+
safetensors==0.4.2
|
42 |
+
six==1.16.0
|
43 |
+
sniffio==1.3.1
|
44 |
+
starlette==0.36.3
|
45 |
+
tensorboard==2.15.2
|
46 |
+
tensorboard-data-server==0.7.2
|
47 |
+
tensorflow==2.15.0.post1
|
48 |
+
tensorflow-estimator==2.15.0
|
49 |
+
tensorflow-io-gcs-filesystem==0.36.0
|
50 |
+
termcolor==2.4.0
|
51 |
+
tokenizers==0.15.2
|
52 |
+
tqdm==4.66.2
|
53 |
+
transformers==4.38.1
|
54 |
+
typing_extensions==4.10.0
|
55 |
+
urllib3==2.2.1
|
56 |
+
uvicorn==0.27.1
|
57 |
+
Werkzeug==3.0.1
|
58 |
+
wrapt==1.14.1
|