File size: 1,094 Bytes
d120873
9f0a178
 
f7cc9ad
d120873
5f8f1a2
f7cc9ad
 
 
d120873
5f8f1a2
d120873
f38941e
d120873
 
2130cf2
9f45cd5
fd2637b
d120873
 
f7cc9ad
5936387
5829d30
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
from fastapi import FastAPI
import src.Paraphrase as Paraphrase
import src.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'}

@app.get("/endpoints")
def index():
    return {'endpoints': ['/paraphrase', '/translate'], 'mtmodels': MTMODELS}

@app.get("/paraphrase")
def paraphrase(text: str, model: str):
    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']):
    # 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()