Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|
| 2 |
import src.Paraphrase as Paraphrase
|
| 3 |
import src.Translate as Translate
|
| 4 |
from typing import Optional
|
|
|
|
| 5 |
|
| 6 |
app = FastAPI(docs_url="/")
|
| 7 |
MTMODELS = {'enro': 'BlackKakapo/opus-mt-en-ro',
|
|
@@ -13,19 +14,22 @@ def index():
|
|
| 13 |
return {'endpoints': ['/paraphrase', '/translate'], 'mtmodels': MTMODELS}
|
| 14 |
|
| 15 |
@app.get("/paraphrase")
|
| 16 |
-
def paraphrase(text: str, model: str):
|
| 17 |
resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
|
| 18 |
return {"input": text, "translation": resultValue, "exception": exception}
|
| 19 |
|
| 20 |
@app.get("/translate")
|
| 21 |
-
def translate(text: str, model: Optional[str] = MTMODELS['gemma']):
|
| 22 |
# resultValue, exception = Translate.paraphraseTranslateMethod(text, model)
|
| 23 |
resultValue = Translate.gemma_direct(text, model)
|
| 24 |
return {"input": text, "result": resultValue, "model": model}
|
| 25 |
|
| 26 |
-
from fastapi_mcp import FastApiMCP
|
| 27 |
# Create an MCP server based on this app
|
| 28 |
-
mcp = FastApiMCP(
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Mount the MCP server directly to your app
|
| 31 |
mcp.mount()
|
|
|
|
| 2 |
import src.Paraphrase as Paraphrase
|
| 3 |
import src.Translate as Translate
|
| 4 |
from typing import Optional
|
| 5 |
+
from fastapi_mcp import FastApiMCP
|
| 6 |
|
| 7 |
app = FastAPI(docs_url="/")
|
| 8 |
MTMODELS = {'enro': 'BlackKakapo/opus-mt-en-ro',
|
|
|
|
| 14 |
return {'endpoints': ['/paraphrase', '/translate'], 'mtmodels': MTMODELS}
|
| 15 |
|
| 16 |
@app.get("/paraphrase")
|
| 17 |
+
def paraphrase(text: str, model: str, operation_id="get_paraphrase"):
|
| 18 |
resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
|
| 19 |
return {"input": text, "translation": resultValue, "exception": exception}
|
| 20 |
|
| 21 |
@app.get("/translate")
|
| 22 |
+
def translate(text: str, model: Optional[str] = MTMODELS['gemma'], operation_id="get_translate"):
|
| 23 |
# resultValue, exception = Translate.paraphraseTranslateMethod(text, model)
|
| 24 |
resultValue = Translate.gemma_direct(text, model)
|
| 25 |
return {"input": text, "result": resultValue, "model": model}
|
| 26 |
|
|
|
|
| 27 |
# Create an MCP server based on this app
|
| 28 |
+
mcp = FastApiMCP(
|
| 29 |
+
app,
|
| 30 |
+
name="FASTAPI translate and paraphrase MCP",
|
| 31 |
+
description="MCP server to translate and paraphrase text",
|
| 32 |
+
include_operations=["get_translate", "get_paraphrase"]
|
| 33 |
+
)
|
| 34 |
# Mount the MCP server directly to your app
|
| 35 |
mcp.mount()
|