TiberiuCristianLeon commited on
Commit
75255bc
·
verified ·
1 Parent(s): 1d71a28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -6,9 +6,10 @@ from fastapi_mcp import FastApiMCP
6
 
7
  app = FastAPI()
8
  # app = FastAPI(docs_url="/docs")
9
- MTMODELS = {'enro': 'BlackKakapo/opus-mt-en-ro',
10
- 'roen': 'BlackKakapo/opus-mt-ro-en',
11
- 'gemma': 'Gargaz/gemma-2b-romanian-better'}
 
12
 
13
  @app.get("/")
14
  def index(request: Request):
@@ -28,7 +29,7 @@ def index(request: Request):
28
  <p><a href="{host_url}/openapi.json" target="_blank">openapi.json</a></p>
29
  <p><a href="{host_url}/mcp" target="_blank">MCP</a></p>
30
  <p>MCP configuration: {mcp_config}</a></p>
31
- <p>MTMODELS: {list(MTMODELS.values())}"</p>
32
  </body>
33
  </html>
34
  '''
@@ -37,20 +38,20 @@ def index(request: Request):
37
  # @app.get("/")
38
  # async def get_host_url(request: Request):
39
  # host_url = request.url.scheme + "s://" + request.url.netloc
40
- # return {"host_url": host_url, 'endpoints': ['/paraphrase', '/translate', f'{host_url}/docs', f'{host_url}/redoc', f'{host_url}/openapi.json'], 'mtmodels': MTMODELS}
41
 
42
  @app.get("/paraphrase", operation_id="get_paraphrase", description="Paraphrase text", tags=["paraphrase"], summary="Paraphrase text")
43
- def paraphrase(text: str, model: str):
44
  resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
45
- return {"input": text, "translation": resultValue, "exception": exception}
46
 
47
  @app.get("/translate", operation_id="get_translate", description="Translate text", tags=["translate"], summary="Translate text")
48
- def translate(text: str, model: Optional[str] = MTMODELS['enro']):
49
  if 'BlackKakapo' in model:
50
  translation = Translate.paraphraseTranslateMethod(text, model)
51
  else:
52
  translation: str = Translate.gemma_direct(text, model)
53
- return {"input": text, "translation": translation, "model": model}
54
 
55
  # Create an MCP server based on this app
56
  mcp = FastApiMCP(
 
6
 
7
  app = FastAPI()
8
  # app = FastAPI(docs_url="/docs")
9
+ MODELS = {'enro': 'BlackKakapo/opus-mt-en-ro',
10
+ 'roen': 'BlackKakapo/opus-mt-ro-en',
11
+ 'gemma': 'Gargaz/gemma-2b-romanian-better',
12
+ 'paraphrase': 'tuner007/pegasus_paraphrase'}
13
 
14
  @app.get("/")
15
  def index(request: Request):
 
29
  <p><a href="{host_url}/openapi.json" target="_blank">openapi.json</a></p>
30
  <p><a href="{host_url}/mcp" target="_blank">MCP</a></p>
31
  <p>MCP configuration: {mcp_config}</a></p>
32
+ <p>MODELS: {list(MODELS.values())}"</p>
33
  </body>
34
  </html>
35
  '''
 
38
  # @app.get("/")
39
  # async def get_host_url(request: Request):
40
  # host_url = request.url.scheme + "s://" + request.url.netloc
41
+ # return {"host_url": host_url, 'endpoints': ['/paraphrase', '/translate', f'{host_url}/docs', f'{host_url}/redoc', f'{host_url}/openapi.json'], 'models': MODELS}
42
 
43
  @app.get("/paraphrase", operation_id="get_paraphrase", description="Paraphrase text", tags=["paraphrase"], summary="Paraphrase text")
44
+ def paraphrase(text: str, model: str = MODELS['paraphrase']):
45
  resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
46
+ return {"input": text, "result": resultValue, "exception": exception}
47
 
48
  @app.get("/translate", operation_id="get_translate", description="Translate text", tags=["translate"], summary="Translate text")
49
+ def translate(text: str, model: Optional[str] = MODELS['enro']):
50
  if 'BlackKakapo' in model:
51
  translation = Translate.paraphraseTranslateMethod(text, model)
52
  else:
53
  translation: str = Translate.gemma_direct(text, model)
54
+ return {"input": text, "result": translation, "model": model}
55
 
56
  # Create an MCP server based on this app
57
  mcp = FastApiMCP(