Spaces:
Running
Running
File size: 1,531 Bytes
d120873 9f0a178 f7cc9ad 8b05c02 d120873 037dcd2 f7cc9ad d120873 2440a8a d120873 2440a8a d120873 184e6ec 698fb3f fd2637b d120873 184e6ec 5936387 786aa14 4e95015 8b05c02 27ced65 c832cd2 8b05c02 4e95015 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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="/docs")
MTMODELS = {'enro': 'BlackKakapo/opus-mt-en-ro',
'roen': 'BlackKakapo/opus-mt-ro-en',
'gemma': 'Gargaz/gemma-2b-romanian-better'}
@app.get("/")
def index():
return {'endpoints': ['/paraphrase', '/translate', '/docs', 'https://tiberiucristianleon-fastapimt.hf.space/redoc'], 'mtmodels': MTMODELS}
@app.get("/paraphrase")
def paraphrase(text: str, model: str, operation_id="get_paraphrase", description="Paraphrase text"):
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", description="Translate text"):
# resultValue, exception = Translate.paraphraseTranslateMethod(text, model)
resultValue: str = 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",
describe_all_responses=True,
describe_full_response_schema=True,
include_operations=["get_translate", "get_paraphrase"]
)
# Mount the MCP server directly to your app
mcp.mount() |