Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,20 @@ app = FastAPI()
|
|
| 7 |
|
| 8 |
token = os.environ.get("HF_TOKEN")
|
| 9 |
|
| 10 |
-
english_model =
|
| 11 |
-
urdu_model =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
@app.post("/predict")
|
| 14 |
async def predict(request: Request):
|
|
@@ -17,8 +29,8 @@ async def predict(request: Request):
|
|
| 17 |
language = body.get("language", "english")
|
| 18 |
|
| 19 |
if language in ["urdu", "roman_urdu"]:
|
| 20 |
-
result =
|
| 21 |
else:
|
| 22 |
-
result =
|
| 23 |
|
| 24 |
return JSONResponse({"label": result["label"], "score": result["score"]})
|
|
|
|
| 7 |
|
| 8 |
token = os.environ.get("HF_TOKEN")
|
| 9 |
|
| 10 |
+
english_model = None
|
| 11 |
+
urdu_model = None
|
| 12 |
+
|
| 13 |
+
def get_english_model():
|
| 14 |
+
global english_model
|
| 15 |
+
if english_model is None:
|
| 16 |
+
english_model = pipeline("text-classification", model="mrgmd01/Finetuned_siebert-sentiment-roberta-large-english", token=token)
|
| 17 |
+
return english_model
|
| 18 |
+
|
| 19 |
+
def get_urdu_model():
|
| 20 |
+
global urdu_model
|
| 21 |
+
if urdu_model is None:
|
| 22 |
+
urdu_model = pipeline("text-classification", model="mrgmd01/SA_Model_bert-base-multilingual-uncased", token=token)
|
| 23 |
+
return urdu_model
|
| 24 |
|
| 25 |
@app.post("/predict")
|
| 26 |
async def predict(request: Request):
|
|
|
|
| 29 |
language = body.get("language", "english")
|
| 30 |
|
| 31 |
if language in ["urdu", "roman_urdu"]:
|
| 32 |
+
result = get_urdu_model()(text)[0]
|
| 33 |
else:
|
| 34 |
+
result = get_english_model()(text)[0]
|
| 35 |
|
| 36 |
return JSONResponse({"label": result["label"], "score": result["score"]})
|