Spaces:
Running
Running
| from fastapi import FastAPI | |
| import src.Paraphrase as Paraphrase | |
| import src.Translate as Translate | |
| from typing import Optional | |
| app = FastAPI() | |
| # 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} | |
| from fastapi_mcp import FastApiMCP | |
| # Create an MCP server based on this app | |
| mcp = FastApiMCP(app) | |
| # Mount the MCP server directly to your app | |
| mcp.mount() |