FastAPIMT / app.py
TiberiuCristianLeon's picture
Update app.py
8b05c02 verified
raw
history blame
1.33 kB
from fastapi import FastAPI
import src.Paraphrase as Paraphrase
import src.Translate as Translate
from typing import Optional
from fastapi_mcp import FastApiMCP
app = FastAPI(docs_url="/")
MTMODELS = {'enro': 'BlackKakapo/opus-mt-en-ro',
'roen': 'BlackKakapo/opus-mt-ro-en',
'gemma': 'Gargaz/gemma-2b-romanian-better'}
@app.get("/endpoints")
def index():
return {'endpoints': ['/paraphrase', '/translate'], 'mtmodels': MTMODELS}
@app.get("/paraphrase")
def paraphrase(text: str, model: str, operation_id="get_paraphrase"):
resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
return {"input": text, "translation": resultValue, "exception": exception}
@app.get("/translate")
def translate(text: str, model: Optional[str] = MTMODELS['gemma'], operation_id="get_translate"):
# resultValue, exception = Translate.paraphraseTranslateMethod(text, model)
resultValue = Translate.gemma_direct(text, model)
return {"input": text, "result": resultValue, "model": model}
# Create an MCP server based on this app
mcp = FastApiMCP(
app,
name="FASTAPI translate and paraphrase MCP",
description="MCP server to translate and paraphrase text",
include_operations=["get_translate", "get_paraphrase"]
)
# Mount the MCP server directly to your app
mcp.mount()