File size: 1,358 Bytes
acc8d06 0aa33ec acc8d06 0aa33ec acc8d06 6721032 0aa33ec 6721032 0aa33ec 6721032 acc8d06 6721032 acc8d06 6721032 |
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 39 40 41 42 43 |
import gradio as gr
import sys
import torch
try:
from unbabel.comet import download_model, load_from_checkpoint
except ImportError:
print("Error: unbabel-comet package not installed")
print("Install with: pip install unbabel-comet torch gradio")
sys.exit(1)
def evaluate_translation(src_text, mt_text):
if not hasattr(evaluate_translation, "model"):
try:
model_path = download_model("wasanx/ComeTH")
evaluate_translation.model = load_from_checkpoint(model_path)
except Exception as e:
return f"Error loading model: {str(e)}"
translations = [{"src": src_text, "mt": mt_text}]
results = evaluate_translation.model.predict(
translations,
batch_size=1,
gpus=0 if not torch.cuda.is_available() else 1
)
return float(results['scores'][0])
demo = gr.Interface(
fn=evaluate_translation,
inputs=[
gr.Textbox(label="English Source Text"),
gr.Textbox(label="Thai Translation")
],
outputs=gr.Number(label="Quality Score"),
examples=[
["This is a test sentence.", "นี่คือประโยคทดสอบ"],
["The weather is nice today.", "อากาศดีมากวันนี้"]
],
title="ComeTH Translator Evaluator"
)
if __name__ == "__main__":
demo.launch() |