Spaces:
Sleeping
Sleeping
Adchayakumar
commited on
Commit
·
5396566
1
Parent(s):
1b179be
Initial FastAPI topic predictor
Browse files- Dockerfile +10 -0
- app.py +36 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY requirements.txt .
|
6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
7 |
+
|
8 |
+
COPY . .
|
9 |
+
|
10 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
# Load model at startup (only once)
|
7 |
+
classifier = pipeline(
|
8 |
+
"zero-shot-classification",
|
9 |
+
model="MoritzLaurer/deberta-v3-large-zeroshot-v1.1-all-33"
|
10 |
+
)
|
11 |
+
|
12 |
+
subject_labels = [
|
13 |
+
"Physics", "Chemistry", "Biology", "Astronomy",
|
14 |
+
"Earth Science", "Environmental Science",
|
15 |
+
"Algebra", "Geometry", "Calculus", "Statistics",
|
16 |
+
"Probability", "Number Theory",
|
17 |
+
"English Language", "English Literature",
|
18 |
+
"Tamil Language", "Tamil Literature",
|
19 |
+
"History", "Geography", "Political Science", "Economics",
|
20 |
+
"Sociology", "Psychology", "Philosophy",
|
21 |
+
"Computer Science", "Data Science", "Artificial Intelligence",
|
22 |
+
"Robotics", "Biotechnology", "Engineering",
|
23 |
+
"Fine Arts", "Music", "Dance", "Theater",
|
24 |
+
"Business Studies", "Accountancy", "Entrepreneurship",
|
25 |
+
"Physical Education", "Health Science"
|
26 |
+
]
|
27 |
+
|
28 |
+
@app.post("/predict/")
|
29 |
+
async def predict_topic(text: str):
|
30 |
+
result = classifier(
|
31 |
+
text,
|
32 |
+
candidate_labels=subject_labels,
|
33 |
+
hypothesis_template="This text is about {}."
|
34 |
+
)
|
35 |
+
predicted_topic = result["labels"][0]
|
36 |
+
return {"topic": predicted_topic}
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
transformers
|
4 |
+
torch
|