File size: 1,845 Bytes
acc8d06
358f50f
f7f6e8d
acc8d06
f7f6e8d
292e32a
acc8d06
292e32a
 
 
f7f6e8d
292e32a
f7f6e8d
 
 
 
 
 
 
 
 
 
292e32a
 
f7f6e8d
 
 
 
292e32a
f7f6e8d
 
 
 
 
 
292e32a
f7f6e8d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
from comet import download_model, load_from_checkpoint
import os

model_path = os.environ.get("HF_MODEL_PATH", download_model("wasanx/ComeTH"))
model = load_from_checkpoint(model_path)

def score_translation(src_text, mt_text):
    translations = [{"src": src_text, "mt": mt_text}]
    results = model.predict(translations, batch_size=1, gpus=1)
    return results['scores'][0]

examples = [
    ["The weather is beautiful today.", "วันนี้อากาศดีมาก"],
    ["I need to go to the hospital.", "ฉันต้องไปโรงพยาบาล"],
    ["This restaurant serves delicious food.", "ร้านอาหารนี้เสิร์ฟอาหารอร่อย"],
    ["Can you help me find the nearest train station?", "คุณช่วยฉันหาสถานีรถไฟที่ใกล้ที่สุดได้ไหม"]
]

with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# ComeTH Translation Quality Evaluator")
    
    with gr.Row():
        with gr.Column():
            src_input = gr.Textbox(label="Source Text (English)", placeholder="Enter English text here...")
            mt_input = gr.Textbox(label="Machine Translation (Thai)", placeholder="Enter Thai translation here...")
            score_button = gr.Button("Evaluate Translation", variant="primary")
        
        with gr.Column():
            score_output = gr.Label(label="Quality Scores")
            gr.Markdown("### Higher scores indicate better translation quality across multiple dimensions")
    
    gr.Examples(examples=examples, inputs=[src_input, mt_input], outputs=score_output, fn=score_translation)
    
    score_button.click(fn=score_translation, inputs=[src_input, mt_input], outputs=score_output)

if __name__ == "__main__":
    demo.launch()