Spaces:
Running
Running
Download app.py from TiberiuCristianLeon/FastAPIMT: direct link, hf CLI and curl.
- Browser
- Download file 903 Bytes
-
https://huggingface.co/spaces/TiberiuCristianLeon/FastAPIMT/resolve/2e5046d5475d378bc717d636f12e9cad97e4e592/app.py
- Command line
-
hf download hf://spaces/TiberiuCristianLeon/FastAPIMT@2e5046d5475d378bc717d636f12e9cad97e4e592/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TiberiuCristianLeon/FastAPIMT/resolve/2e5046d5475d378bc717d636f12e9cad97e4e592/app.py
903 Bytes
| from fastapi import FastAPI | |
| import src.paraphrase.Paraphrase as Paraphrase | |
| import src.translate.Translate as Translate | |
| import nltk | |
| nltk.download('punkt') | |
| nltk.download('punkt_tab') | |
| app = FastAPI(docs_url="/") | |
| MTMODELS = {'enro': 'BlackKakapo/opus-mt-en-ro', 'roen': 'BlackKakapo/opus-mt-ro-en'} | |
| 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: str): | |
| # resultValue, exception = Translate.paraphraseTranslateMethod(text, model) | |
| resultValue, exception = Translate.gemma(text, model) | |
| return {"input": text, "translation": resultValue, "exception": exception} |