Spaces:
Running
Running
Download app.py from TiberiuCristianLeon/FastAPIMT: direct link, hf CLI and curl.
- Browser
- Download file 950 Bytes
-
https://huggingface.co/spaces/TiberiuCristianLeon/FastAPIMT/resolve/ad83d272907f3c1d9c31b4d26080c52dd949a48d/app.py
- Command line
-
hf download hf://spaces/TiberiuCristianLeon/FastAPIMT@ad83d272907f3c1d9c31b4d26080c52dd949a48d/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TiberiuCristianLeon/FastAPIMT/resolve/ad83d272907f3c1d9c31b4d26080c52dd949a48d/app.py
950 Bytes
| from fastapi import FastAPI | |
| import src.paraphrase.Paraphrase as Paraphrase | |
| import src.translate.Translate as Translate | |
| from typing import Optional | |
| app = FastAPI(docs_url="/") | |
| MTMODELS = {'enro': 'BlackKakapo/opus-mt-en-ro', | |
| 'roen': 'BlackKakapo/opus-mt-ro-en', | |
| 'gemma': 'Gargaz/gemma-2b-romanian-better'} | |
| def index(): | |
| return {'endpoints': ['/paraphrase', '/translate'], 'mtmodels': MTMODELS} | |
| def paraphrase(text: str, model: str): | |
| resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model) | |
| return {"input": text, "translation": resultValue, "exception": exception} | |
| def translate(text: str, model: Optional[str] = MTMODELS['gemma']): | |
| # resultValue, exception = Translate.paraphraseTranslateMethod(text, model) | |
| resultValue = Translate.gemma_direct(text, model) | |
| return {"input": text, "result": resultValue, "model": model} |