|
|
import gradio as gr |
|
|
from comet import download_model, load_from_checkpoint |
|
|
|
|
|
|
|
|
model_path = download_model("Unbabel/wmt20-comet-qe-da") |
|
|
model = load_from_checkpoint(model_path) |
|
|
|
|
|
def score(src, mt): |
|
|
if not src or not mt: |
|
|
return "❗请输入源文与译文" |
|
|
data = [{"src": src, "mt": mt}] |
|
|
score = model.predict(data, gpus=0)["scores"][0] |
|
|
|
|
|
|
|
|
if score > 0.8: |
|
|
level = "🌟 质量非常好(几乎无需修改)" |
|
|
elif score > 0.6: |
|
|
level = "👍 质量良好(小幅调整即可)" |
|
|
elif score > 0.4: |
|
|
level = "🟡 中等(可能有语义偏移)" |
|
|
else: |
|
|
level = "🔴 质量较差(存在明显翻译错误)" |
|
|
|
|
|
return f"模型评分:{score:.4f}\n评估:{level}" |
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=score, |
|
|
inputs=[ |
|
|
gr.Textbox(label="源文本(Source)", placeholder="请输入原文..."), |
|
|
gr.Textbox(label="机器翻译文本(Translation)", placeholder="请输入翻译结果..."), |
|
|
], |
|
|
outputs=gr.Textbox(label="翻译质量评估结果"), |
|
|
title="Unbabel COMET-QE 机器翻译质量检测", |
|
|
description=""" |
|
|
### 📘 基于 Unbabel COMET-QE 的无参考机器翻译质量评估 |
|
|
只需输入 **源文 + 译文**,模型自动给出 0~1 分的质量评估。 |
|
|
- 0.8+:非常好 |
|
|
- 0.6~0.8:较好 |
|
|
- 0.4~0.6:一般 |
|
|
- <0.4:较差 |
|
|
""", |
|
|
) |
|
|
|
|
|
demo.launch() |
|
|
|