Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from comet import download_model, load_from_checkpoint
|
| 3 |
+
|
| 4 |
+
model_path = download_model("wasanx/ComeTH")
|
| 5 |
+
model = load_from_checkpoint(model_path)
|
| 6 |
+
|
| 7 |
+
def score_translation(src_text, mt_text):
|
| 8 |
+
translations = [{
|
| 9 |
+
"src": src_text,
|
| 10 |
+
"mt": mt_text,
|
| 11 |
+
}]
|
| 12 |
+
results = model.predict(translations, batch_size=1, gpus=1)
|
| 13 |
+
scores = results.get('scores', [[]])[0]
|
| 14 |
+
output = {f"Score {i+1}": score for i, score in enumerate(scores)}
|
| 15 |
+
return output
|
| 16 |
+
|
| 17 |
+
def main():
|
| 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 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
main()
|