Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -131,20 +131,20 @@ class Bergamot:
|
|
| 131 |
response, message_text = str(downloaderror), f"Error downloading {self.model_name}: {downloaderror}."
|
| 132 |
print(downloaderror)
|
| 133 |
def translate(self):
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
|
| 149 |
# 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
|
| 150 |
@app.get("/bergamot", operation_id="get_bergamot", description="Translate text with Bergamot", tags=["bergamot"], summary="Translate text with Bergamot")
|
|
|
|
| 131 |
response, message_text = str(downloaderror), f"Error downloading {self.model_name}: {downloaderror}."
|
| 132 |
print(downloaderror)
|
| 133 |
def translate(self):
|
| 134 |
+
try:
|
| 135 |
+
model = self.service.modelFromConfigPath(f"{self.localfolder}/config.yml")
|
| 136 |
+
# model = self.service.modelFromConfig(localfolder)
|
| 137 |
+
options = bergamot.ResponseOptions(alignment=False, sentenceMappings=False, qualityScores=False, HTML=False)
|
| 138 |
+
rawresponse = self.service.translate(model, bergamot.VectorString(self.input_text), options)
|
| 139 |
+
response: list|str = [r.target.text for r in rawresponse] if len(rawresponse) > 1 else next(iter(rawresponse)).target.text
|
| 140 |
+
print(type(self.input_text), len(self.input_text), len(rawresponse), type(response), response)
|
| 141 |
+
# response = [r.target.text for r in model_response][0] if isinstance(response, bergamot._bergamot.VectorResponse) else next(iter(response)).target.text
|
| 142 |
+
# response is of type bergamot._bergamot.VectorResponse, an iterable of bergamot._bergamot.Response
|
| 143 |
+
message_text = f"Translated from {self.sl} to {self.tl} with {self.model_name}."
|
| 144 |
+
except Exception as translateerror:
|
| 145 |
+
response, message_text = str(translateerror), f"Error translating from {self.sl} to {self.tl} with {self.model_name}: {translateerror}."
|
| 146 |
+
print(translateerror)
|
| 147 |
+
return {"input": self.input_text, "translated_text": response, "message_text": message_text}
|
| 148 |
|
| 149 |
# 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
|
| 150 |
@app.get("/bergamot", operation_id="get_bergamot", description="Translate text with Bergamot", tags=["bergamot"], summary="Translate text with Bergamot")
|