Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI, Request, Query
|
| 2 |
import src.Paraphrase as Paraphrase
|
| 3 |
-
import src.
|
|
|
|
| 4 |
from typing import Optional
|
| 5 |
from fastapi_mcp import FastApiMCP
|
| 6 |
from huggingface_hub import hf_hub_download, list_repo_files
|
|
@@ -8,8 +9,9 @@ from sentence_transformers import SentenceTransformer
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
# app = FastAPI(docs_url="/docs")
|
| 11 |
-
MODELS = {'
|
| 12 |
-
'
|
|
|
|
| 13 |
'gemma': 'Gargaz/gemma-2b-romanian-better',
|
| 14 |
'paraphrase': 'tuner007/pegasus_paraphrase'}
|
| 15 |
EMBEDDING_MODELS = {"all-MiniLM-L6-v2":384,
|
|
@@ -54,10 +56,17 @@ def paraphrase(text: str, model: str = MODELS['paraphrase']):
|
|
| 54 |
resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
|
| 55 |
return {"input": text, "result": resultValue, "exception": exception}
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
@app.get("/translate", operation_id="get_translate", description="Translate text", tags=["translate"], summary="Translate text")
|
| 58 |
-
def translate(
|
| 59 |
-
if 'BlackKakapo' in
|
| 60 |
-
translation =
|
|
|
|
|
|
|
| 61 |
else:
|
| 62 |
translation: str = Translate.gemma_direct(text, model)
|
| 63 |
return {"input": text, "result": translation, "model": model}
|
|
|
|
| 1 |
from fastapi import FastAPI, Request, Query
|
| 2 |
import src.Paraphrase as Paraphrase
|
| 3 |
+
import src.Translation as Translation
|
| 4 |
+
import src.Translate as Cltranslate
|
| 5 |
from typing import Optional
|
| 6 |
from fastapi_mcp import FastApiMCP
|
| 7 |
from huggingface_hub import hf_hub_download, list_repo_files
|
|
|
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
# app = FastAPI(docs_url="/docs")
|
| 12 |
+
MODELS = {'benro': 'BlackKakapo/opus-mt-en-ro',
|
| 13 |
+
'broen': 'BlackKakapo/opus-mt-ro-en',
|
| 14 |
+
'mttcbig': 'Helsinki-NLP/opus-mt-tc-big-en-ro',
|
| 15 |
'gemma': 'Gargaz/gemma-2b-romanian-better',
|
| 16 |
'paraphrase': 'tuner007/pegasus_paraphrase'}
|
| 17 |
EMBEDDING_MODELS = {"all-MiniLM-L6-v2":384,
|
|
|
|
| 56 |
resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
|
| 57 |
return {"input": text, "result": resultValue, "exception": exception}
|
| 58 |
|
| 59 |
+
@app.get("/listmodels", operation_id="list_models", description="List models", tags=["listmodels"], summary="List models")
|
| 60 |
+
def listmodels():
|
| 61 |
+
return {"MODELS": MODELS, "EMBEDDING_MODELS": EMBEDDING_MODELS}
|
| 62 |
+
|
| 63 |
+
# text: str, model: Optional[str] = MODELS['benro']
|
| 64 |
@app.get("/translate", operation_id="get_translate", description="Translate text", tags=["translate"], summary="Translate text")
|
| 65 |
+
def translate(input_text: str, model_name: str = MODELS['mttcbig'], sl: str = 'en', tl: str = 'ro'):
|
| 66 |
+
if 'BlackKakapo' in model_name:
|
| 67 |
+
translation = Translation.paraphraseTranslateMethod(text, model_name)
|
| 68 |
+
elif 'Helsinki-NLP' in model_name:
|
| 69 |
+
translation = Cltranslate.HelsinkiNLP_mulroa(model_name, sl, tl, input_text)
|
| 70 |
else:
|
| 71 |
translation: str = Translate.gemma_direct(text, model)
|
| 72 |
return {"input": text, "result": translation, "model": model}
|