Commit
·
f43b328
1
Parent(s):
34a52a1
Update alma output
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import os
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from fastapi.responses import JSONResponse
|
| 6 |
|
| 7 |
-
print("Version ----
|
| 8 |
app = FastAPI()
|
| 9 |
|
| 10 |
def download_file_from_hf(repo_id, filename):
|
|
@@ -27,7 +27,7 @@ download_file_from_hf("SinaLab/ArabGlossBERT","four_grams.pickle")
|
|
| 27 |
download_file_from_hf("SinaLab/ArabGlossBERT","five_grams.pickle")
|
| 28 |
|
| 29 |
from sinatools.morphology.morph_analyzer import analyze
|
| 30 |
-
|
| 31 |
|
| 32 |
class ALMARequest(BaseModel):
|
| 33 |
text: str
|
|
@@ -42,12 +42,22 @@ def predict(request: ALMARequest):
|
|
| 42 |
task = request.task
|
| 43 |
flag = request.flag
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
return JSONResponse(
|
| 53 |
content=content,
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from fastapi.responses import JSONResponse
|
| 6 |
|
| 7 |
+
print("Version ---- 2")
|
| 8 |
app = FastAPI()
|
| 9 |
|
| 10 |
def download_file_from_hf(repo_id, filename):
|
|
|
|
| 27 |
download_file_from_hf("SinaLab/ArabGlossBERT","five_grams.pickle")
|
| 28 |
|
| 29 |
from sinatools.morphology.morph_analyzer import analyze
|
| 30 |
+
from sinatools.utils.tokenizer import sentence_tokenizer
|
| 31 |
|
| 32 |
class ALMARequest(BaseModel):
|
| 33 |
text: str
|
|
|
|
| 42 |
task = request.task
|
| 43 |
flag = request.flag
|
| 44 |
|
| 45 |
+
sentences = sentence_tokenizer(text, dot=True, new_line=True, question_mark=True, exclamation_mark=True)
|
| 46 |
+
|
| 47 |
+
results_with_sentences = []
|
| 48 |
+
|
| 49 |
+
for i, sentence in enumerate(sentences):
|
| 50 |
+
sentence_id = i + 1
|
| 51 |
+
|
| 52 |
+
result = analyze(sentence, language, task, str(flag))
|
| 53 |
+
|
| 54 |
+
results_with_sentences.append({
|
| 55 |
+
"sentence_id": sentence_id,
|
| 56 |
+
"sentence": sentence,
|
| 57 |
+
"lemmatizer_results": result
|
| 58 |
+
})
|
| 59 |
+
|
| 60 |
+
content = {"resp": results_with_sentences, "statusText": "OK", "statusCode": 0}
|
| 61 |
|
| 62 |
return JSONResponse(
|
| 63 |
content=content,
|