Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import src.Paraphrase as Paraphrase
|
|
3 |
import src.Translate as Translate
|
4 |
from typing import Optional
|
5 |
from fastapi_mcp import FastApiMCP
|
6 |
-
from typing import Union
|
7 |
|
8 |
app = FastAPI()
|
9 |
# app = FastAPI(docs_url="/docs")
|
@@ -56,7 +55,6 @@ def translate(text: str, model: Optional[str] = MODELS['enro']):
|
|
56 |
|
57 |
# https://tiberiucristianleon-fastapimt.hf.space/bergamot?input_text=das%20ist%20keine%20gute%20Frau&input_text=das%20ist%20eine%20gute%20Nachricht&sl=de&tl=en&model=bergamot
|
58 |
@app.get("/bergamot", operation_id="get_bergamot", description="Translate text with Bergamot", tags=["bergamot"], summary="Translate text with Bergamot")
|
59 |
-
# def bergamot(input_text: str, sl: str = 'de', tl: str = 'en', model: Optional[str] = 'bergamot'):
|
60 |
def bergamot(input_text: list[str] = Query(description="Input list of strings"), sl: str = 'de', tl: str = 'en', model: Optional[str] = 'bergamot'):
|
61 |
try:
|
62 |
import bergamot
|
@@ -66,9 +64,9 @@ def bergamot(input_text: list[str] = Query(description="Input list of strings"),
|
|
66 |
service = bergamot.Service(config)
|
67 |
models = service.modelFromConfigPath("./deen/bergamot.config.yml")
|
68 |
options = bergamot.ResponseOptions(alignment=False, qualityScores=False, HTML=False)
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
# response = [r.target.text for r in model_response][0] if isinstance(response, bergamot._bergamot.VectorResponse) else next(iter(response)).target.text
|
73 |
# response is of type bergamot._bergamot.VectorResponse, an iterable of bergamot._bergamot.Response
|
74 |
except Exception as error:
|
@@ -83,7 +81,7 @@ mcp = FastApiMCP(
|
|
83 |
describe_all_responses=True,
|
84 |
describe_full_response_schema=True,
|
85 |
include_operations=["get_translate", "get_paraphrase"],
|
86 |
-
include_tags=["paraphrase", "translate"]
|
87 |
)
|
88 |
# Mount the MCP server directly to the FASTAPI app
|
89 |
mcp.mount()
|
|
|
3 |
import src.Translate as Translate
|
4 |
from typing import Optional
|
5 |
from fastapi_mcp import FastApiMCP
|
|
|
6 |
|
7 |
app = FastAPI()
|
8 |
# app = FastAPI(docs_url="/docs")
|
|
|
55 |
|
56 |
# https://tiberiucristianleon-fastapimt.hf.space/bergamot?input_text=das%20ist%20keine%20gute%20Frau&input_text=das%20ist%20eine%20gute%20Nachricht&sl=de&tl=en&model=bergamot
|
57 |
@app.get("/bergamot", operation_id="get_bergamot", description="Translate text with Bergamot", tags=["bergamot"], summary="Translate text with Bergamot")
|
|
|
58 |
def bergamot(input_text: list[str] = Query(description="Input list of strings"), sl: str = 'de', tl: str = 'en', model: Optional[str] = 'bergamot'):
|
59 |
try:
|
60 |
import bergamot
|
|
|
64 |
service = bergamot.Service(config)
|
65 |
models = service.modelFromConfigPath("./deen/bergamot.config.yml")
|
66 |
options = bergamot.ResponseOptions(alignment=False, qualityScores=False, HTML=False)
|
67 |
+
rawresponse = service.translate(models, bergamot.VectorString(input_text), options)
|
68 |
+
response = [r.target.text for r in rawresponse] if len(rawresponse) > 1 else next(iter(rawresponse)).target.text
|
69 |
+
print(type(input_text), len(input_text), len(rawresponse), response])
|
70 |
# response = [r.target.text for r in model_response][0] if isinstance(response, bergamot._bergamot.VectorResponse) else next(iter(response)).target.text
|
71 |
# response is of type bergamot._bergamot.VectorResponse, an iterable of bergamot._bergamot.Response
|
72 |
except Exception as error:
|
|
|
81 |
describe_all_responses=True,
|
82 |
describe_full_response_schema=True,
|
83 |
include_operations=["get_translate", "get_paraphrase"],
|
84 |
+
include_tags=["paraphrase", "translate", "bergamot"]
|
85 |
)
|
86 |
# Mount the MCP server directly to the FASTAPI app
|
87 |
mcp.mount()
|