WENior commited on
Commit
98ffcc5
·
verified ·
1 Parent(s): 4a48069

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from comet import download_model, load_from_checkpoint
3
+
4
+ # ---- 加载模型(启动时执行一次) ----
5
+ model_path = download_model("Unbabel/wmt20-comet-qe-da")
6
+ model = load_from_checkpoint(model_path)
7
+
8
+ def score(src, mt):
9
+ if not src or not mt:
10
+ return "❗请输入源文与译文"
11
+ data = [{"src": src, "mt": mt}]
12
+ score = model.predict(data, gpus=0)["scores"][0]
13
+
14
+ # 可读性解释
15
+ if score > 0.8:
16
+ level = "🌟 质量非常好(几乎无需修改)"
17
+ elif score > 0.6:
18
+ level = "👍 质量良好(小幅调整即可)"
19
+ elif score > 0.4:
20
+ level = "🟡 中等(可能有语义偏移)"
21
+ else:
22
+ level = "🔴 质量较差(存在明显翻译错误)"
23
+
24
+ return f"模型评分:{score:.4f}\n评估:{level}"
25
+
26
+ # ---- Gradio前端 ----
27
+ demo = gr.Interface(
28
+ fn=score,
29
+ inputs=[
30
+ gr.Textbox(label="源文本(Source)", placeholder="请输入原文..."),
31
+ gr.Textbox(label="机器翻译文本(Translation)", placeholder="请输入翻译结果..."),
32
+ ],
33
+ outputs=gr.Textbox(label="翻译质量评估结果"),
34
+ title="Unbabel COMET-QE 机器翻译质量检测",
35
+ description="""
36
+ ### 📘 基于 Unbabel COMET-QE 的无参考机器翻译质量评估
37
+ 只需输入 **源文 + 译文**,模型自动给出 0~1 分的质量评估。
38
+ - 0.8+:非常好
39
+ - 0.6~0.8:较好
40
+ - 0.4~0.6:一般
41
+ - <0.4:较差
42
+ """,
43
+ )
44
+
45
+ demo.launch()