Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,21 +54,15 @@ def translate(text: str, model: Optional[str] = MODELS['enro']):
|
|
| 54 |
return {"input": text, "result": translation, "model": model}
|
| 55 |
|
| 56 |
@app.get("/bergamot", operation_id="get_bergamot", description="Translate text with Bergamot", tags=["bergamot"], summary="Translate text with Bergamot")
|
| 57 |
-
def bergamot(text: str, model: Optional[str] = 'bergamot'):
|
| 58 |
try:
|
| 59 |
import bergamot
|
| 60 |
config = bergamot.ServiceConfig(numWorkers=4)
|
| 61 |
service = bergamot.Service(config)
|
| 62 |
models = service.modelFromConfigPath("./deen/bergamot.config.yml")
|
| 63 |
-
options = bergamot.ResponseOptions(
|
| 64 |
-
|
| 65 |
-
)
|
| 66 |
-
response = service.translate(models, bergamot.VectorString([
|
| 67 |
-
"Das ist ein deutscher Text",
|
| 68 |
-
"Das ist der zweite Satz.",
|
| 69 |
-
text,
|
| 70 |
-
]), options)
|
| 71 |
-
responselist = [r.target.text for r in response]
|
| 72 |
except Exception as error:
|
| 73 |
response = error
|
| 74 |
return {"input": text, "result": responselist, "model": str(model)}
|
|
|
|
| 54 |
return {"input": text, "result": translation, "model": model}
|
| 55 |
|
| 56 |
@app.get("/bergamot", operation_id="get_bergamot", description="Translate text with Bergamot", tags=["bergamot"], summary="Translate text with Bergamot")
|
| 57 |
+
def bergamot(text: str, sl: str = 'de', tl: str = 'en', model: Optional[str] = 'bergamot'):
|
| 58 |
try:
|
| 59 |
import bergamot
|
| 60 |
config = bergamot.ServiceConfig(numWorkers=4)
|
| 61 |
service = bergamot.Service(config)
|
| 62 |
models = service.modelFromConfigPath("./deen/bergamot.config.yml")
|
| 63 |
+
options = bergamot.ResponseOptions(alignment=False, qualityScores=False, HTML=False)
|
| 64 |
+
response = service.translate(models, bergamot.VectorString(text), options)
|
| 65 |
+
responselist = [r.target.text for r in response] if isinstance(response, list) else responselist
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
except Exception as error:
|
| 67 |
response = error
|
| 68 |
return {"input": text, "result": responselist, "model": str(model)}
|