Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from comet import download_model, load_from_checkpoint
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
translations = [{
|
| 9 |
-
"src": src_text,
|
| 10 |
-
"mt": mt_text,
|
| 11 |
-
}]
|
| 12 |
results = model.predict(translations, batch_size=1, gpus=1)
|
| 13 |
-
|
| 14 |
-
output = {f"Score {i+1}": score for i, score in enumerate(scores)}
|
| 15 |
-
return output
|
| 16 |
|
| 17 |
-
|
| 18 |
-
with gr.Blocks() as demo:
|
| 19 |
-
gr.Markdown("# Translation Quality Scoring with ComeTH Model")
|
| 20 |
-
with gr.Row():
|
| 21 |
-
with gr.Column():
|
| 22 |
-
src_input = gr.Textbox(label="Source Text (English)")
|
| 23 |
-
mt_input = gr.Textbox(label="Machine Translation Text (Thai)")
|
| 24 |
-
with gr.Column():
|
| 25 |
-
score_output = gr.Label(num_top_classes=5, label="Quality Scores")
|
| 26 |
-
score_button = gr.Button("Score Translation")
|
| 27 |
-
score_button.click(fn=score_translation,
|
| 28 |
-
inputs=[src_input, mt_input],
|
| 29 |
-
outputs=[score_output])
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from comet import download_model, load_from_checkpoint
|
| 3 |
|
| 4 |
+
def load_cometh_model():
|
| 5 |
+
model_path = download_model("wasanx/ComeTH")
|
| 6 |
+
return load_from_checkpoint(model_path)
|
| 7 |
|
| 8 |
+
def evaluate_translation(src_text, mt_text):
|
| 9 |
+
translations = [{"src": src_text, "mt": mt_text}]
|
|
|
|
|
|
|
|
|
|
| 10 |
results = model.predict(translations, batch_size=1, gpus=1)
|
| 11 |
+
return float(results['scores'][0])
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
model = load_cometh_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
demo = gr.Interface(
|
| 16 |
+
fn=evaluate_translation,
|
| 17 |
+
inputs=[
|
| 18 |
+
gr.Textbox(label="English Source Text"),
|
| 19 |
+
gr.Textbox(label="Thai Translation")
|
| 20 |
+
],
|
| 21 |
+
outputs=gr.Number(label="Quality Score"),
|
| 22 |
+
examples=[
|
| 23 |
+
["This is a test sentence.", "นี่คือประโยคทดสอบ"],
|
| 24 |
+
["The weather is nice today.", "อากาศดีมากวันนี้"]
|
| 25 |
+
],
|
| 26 |
+
title="ComeTH Translator Evaluator"
|
| 27 |
+
)
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|
| 30 |
+
demo.launch()
|