Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,11 +20,13 @@ def index(request: Request):
|
|
20 |
<title>FastAPI with MCP</title>
|
21 |
</head>
|
22 |
<body>
|
23 |
-
<
|
24 |
<p>Host URL: {host_url}</p>
|
25 |
<p><a href="{host_url}/docs">DOCS</a></p>
|
26 |
<p><a href="{host_url}/redoc">REDOC</a></p>
|
27 |
<p><a href="{host_url}/openapi.json">openapi.json</a></p>
|
|
|
|
|
28 |
</body>
|
29 |
</html>
|
30 |
'''
|
@@ -36,12 +38,12 @@ def index(request: Request):
|
|
36 |
# return {"host_url": host_url, 'endpoints': ['/paraphrase', '/translate', f'{host_url}/docs', f'{host_url}/redoc', f'{host_url}/openapi.json'], 'mtmodels': MTMODELS}
|
37 |
|
38 |
@app.get("/paraphrase")
|
39 |
-
def paraphrase(text: str, model: str, operation_id="get_paraphrase", description="Paraphrase text"):
|
40 |
resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
|
41 |
return {"input": text, "translation": resultValue, "exception": exception}
|
42 |
|
43 |
@app.get("/translate")
|
44 |
-
def translate(text: str, model: Optional[str] = MTMODELS['gemma'], operation_id="get_translate", description="Translate text"):
|
45 |
# resultValue, exception = Translate.paraphraseTranslateMethod(text, model)
|
46 |
resultValue: str = Translate.gemma_direct(text, model)
|
47 |
return {"input": text, "result": resultValue, "model": model}
|
@@ -53,7 +55,8 @@ mcp = FastApiMCP(
|
|
53 |
description="MCP server to translate and paraphrase text",
|
54 |
describe_all_responses=True,
|
55 |
describe_full_response_schema=True,
|
56 |
-
include_operations=["get_translate", "get_paraphrase"]
|
|
|
57 |
)
|
58 |
# Mount the MCP server directly to your app
|
59 |
mcp.mount()
|
|
|
20 |
<title>FastAPI with MCP</title>
|
21 |
</head>
|
22 |
<body>
|
23 |
+
<h2>FastAPI URLS</h2>
|
24 |
<p>Host URL: {host_url}</p>
|
25 |
<p><a href="{host_url}/docs">DOCS</a></p>
|
26 |
<p><a href="{host_url}/redoc">REDOC</a></p>
|
27 |
<p><a href="{host_url}/openapi.json">openapi.json</a></p>
|
28 |
+
<p><a href="{host_url}/mcp">MCP</a></p>
|
29 |
+
<p>MTMODELS: {MTMODELS}"</p>
|
30 |
</body>
|
31 |
</html>
|
32 |
'''
|
|
|
38 |
# return {"host_url": host_url, 'endpoints': ['/paraphrase', '/translate', f'{host_url}/docs', f'{host_url}/redoc', f'{host_url}/openapi.json'], 'mtmodels': MTMODELS}
|
39 |
|
40 |
@app.get("/paraphrase")
|
41 |
+
def paraphrase(text: str, model: str, operation_id="get_paraphrase", description="Paraphrase text", tags=["paraphrase"], summary="Paraphrase text"):
|
42 |
resultValue, exception = Paraphrase.paraphraseParaphraseMethod(text, model)
|
43 |
return {"input": text, "translation": resultValue, "exception": exception}
|
44 |
|
45 |
@app.get("/translate")
|
46 |
+
def translate(text: str, model: Optional[str] = MTMODELS['gemma'], operation_id="get_translate", description="Translate text", tags=["translate"], summary="Translate text"):
|
47 |
# resultValue, exception = Translate.paraphraseTranslateMethod(text, model)
|
48 |
resultValue: str = Translate.gemma_direct(text, model)
|
49 |
return {"input": text, "result": resultValue, "model": model}
|
|
|
55 |
description="MCP server to translate and paraphrase text",
|
56 |
describe_all_responses=True,
|
57 |
describe_full_response_schema=True,
|
58 |
+
include_operations=["get_translate", "get_paraphrase"],
|
59 |
+
include_tags=["paraphrase", "translate"]
|
60 |
)
|
61 |
# Mount the MCP server directly to your app
|
62 |
mcp.mount()
|