Spaces:
Paused
Paused
nairut
commited on
Commit
·
c4fb99d
1
Parent(s):
90635cc
Adiciona API XCOMET-XXL-app
Browse files- Novo Documento de Texto (2).txt +0 -0
- Novo Documento de Texto.txt +0 -0
- app.py +26 -0
Novo Documento de Texto (2).txt
ADDED
|
File without changes
|
Novo Documento de Texto.txt
ADDED
|
File without changes
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from comet import download_model, load_from_checkpoint
|
| 4 |
+
|
| 5 |
+
# Inicializa FastAPI
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Carrega o modelo (uma vez só ao iniciar)
|
| 9 |
+
model_path = download_model("Unbabel/XCOMET-XXL")
|
| 10 |
+
model = load_from_checkpoint(model_path)
|
| 11 |
+
|
| 12 |
+
# Define formato da requisição
|
| 13 |
+
class TranslationPair(BaseModel):
|
| 14 |
+
src: str
|
| 15 |
+
mt: str
|
| 16 |
+
ref: str = None # opcional
|
| 17 |
+
|
| 18 |
+
@app.post("/score")
|
| 19 |
+
def score_translation(pair: TranslationPair):
|
| 20 |
+
data = [{"src": pair.src, "mt": pair.mt, "ref": pair.ref}]
|
| 21 |
+
output = model.predict(data, batch_size=8, gpus=1)
|
| 22 |
+
return {
|
| 23 |
+
"segment_scores": output.scores,
|
| 24 |
+
"system_score": output.system_score,
|
| 25 |
+
"error_spans": getattr(output.metadata, "error_spans", None)
|
| 26 |
+
}
|