Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,21 +55,34 @@ def translate(text: str, model: Optional[str] = MODELS['enro']):
|
|
| 55 |
|
| 56 |
@app.get("/test", operation_id="get_test", description="Test text", tags=["test"], summary="Test text")
|
| 57 |
def test(text: str, model: Optional[str] = 'bergamot'):
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
"
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
return {"input": text, "result": response, "model": model}
|
| 74 |
|
| 75 |
# Create an MCP server based on this app
|
|
|
|
| 55 |
|
| 56 |
@app.get("/test", operation_id="get_test", description="Test text", tags=["test"], summary="Test text")
|
| 57 |
def test(text: str, model: Optional[str] = 'bergamot'):
|
| 58 |
+
try:
|
| 59 |
+
# import bergamot
|
| 60 |
+
# config = bergamot.ServiceConfig(numWorkers=2)
|
| 61 |
+
# service = bergamot.Service(config)
|
| 62 |
+
# model = service.modelFromConfigPath("bergamot.config.yaml")
|
| 63 |
+
# options = bergamot.ResponseOptions(
|
| 64 |
+
# alignment=False, qualityScores=False, HTML=False
|
| 65 |
+
# )
|
| 66 |
+
# response = service.translate(model, bergamot.VectorString([
|
| 67 |
+
# "Das ist ein deutscher Text",
|
| 68 |
+
# "In the last 3 months, over 80 arrestees were released.",
|
| 69 |
+
# text,
|
| 70 |
+
# ]), options)
|
| 71 |
+
|
| 72 |
+
# for r in response:
|
| 73 |
+
# print(r.target.text)
|
| 74 |
+
from bergamot import Translator
|
| 75 |
|
| 76 |
+
translator = Translator(
|
| 77 |
+
models=["model.deen.intgemm.alphas.bin"],
|
| 78 |
+
vocabs=["vocab.deen.spm", "vocab.deen.spm"],
|
| 79 |
+
shortlist="lex.50.50.deen.s2t.bin",
|
| 80 |
+
beam_size=1,
|
| 81 |
+
normalize=1.0
|
| 82 |
+
)
|
| 83 |
+
response = translator.translate([text])
|
| 84 |
+
except Exception as error:
|
| 85 |
+
response = error
|
| 86 |
return {"input": text, "result": response, "model": model}
|
| 87 |
|
| 88 |
# Create an MCP server based on this app
|