Update app.py
Browse files
app.py
CHANGED
|
@@ -591,4 +591,69 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
|
| 591 |
btn2 = gr.Button("Drilling (Long)", size="sm")
|
| 592 |
btn3 = gr.Button("Reservoir (Short)", size="sm")
|
| 593 |
btn4 = gr.Button("Reservoir (Long)", size="sm")
|
| 594 |
-
btn5 = gr.Button("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
btn2 = gr.Button("Drilling (Long)", size="sm")
|
| 592 |
btn3 = gr.Button("Reservoir (Short)", size="sm")
|
| 593 |
btn4 = gr.Button("Reservoir (Long)", size="sm")
|
| 594 |
+
btn5 = gr.Button("Subsea (Short)", size="sm")
|
| 595 |
+
|
| 596 |
+
with gr.Row():
|
| 597 |
+
btn6 = gr.Button("Subsea (Long)", size="sm")
|
| 598 |
+
btn7 = gr.Button("Seismic (Short)", size="sm")
|
| 599 |
+
btn8 = gr.Button("Seismic (Long)", size="sm")
|
| 600 |
+
btn9 = gr.Button("Safety (Short)", size="sm")
|
| 601 |
+
btn10 = gr.Button("Safety (Long)", size="sm")
|
| 602 |
+
|
| 603 |
+
btn1.click(lambda sl: get_example("drilling_short", sl), inputs=[source_lang], outputs=example_text)
|
| 604 |
+
btn2.click(lambda sl: get_example("drilling_long", sl), inputs=[source_lang], outputs=example_text)
|
| 605 |
+
btn3.click(lambda sl: get_example("reservoir_short", sl), inputs=[source_lang], outputs=example_text)
|
| 606 |
+
btn4.click(lambda sl: get_example("reservoir_long", sl), inputs=[source_lang], outputs=example_text)
|
| 607 |
+
btn5.click(lambda sl: get_example("subsea_short", sl), inputs=[source_lang], outputs=example_text)
|
| 608 |
+
btn6.click(lambda sl: get_example("subsea_long", sl), inputs=[source_lang], outputs=example_text)
|
| 609 |
+
btn7.click(lambda sl: get_example("seismic_short", sl), inputs=[source_lang], outputs=example_text)
|
| 610 |
+
btn8.click(lambda sl: get_example("seismic_long", sl), inputs=[source_lang], outputs=example_text)
|
| 611 |
+
btn9.click(lambda sl: get_example("safety_short", sl), inputs=[source_lang], outputs=example_text)
|
| 612 |
+
btn10.click(lambda sl: get_example("safety_long", sl), inputs=[source_lang], outputs=example_text)
|
| 613 |
+
|
| 614 |
+
use_example_btn.click(fn=lambda x: x, inputs=example_text, outputs=input_text)
|
| 615 |
+
|
| 616 |
+
with gr.Accordion("Upload Text File", open=False):
|
| 617 |
+
file_input = gr.File(
|
| 618 |
+
label="Upload a .txt file to translate (max 1MB)",
|
| 619 |
+
file_types=[".txt"],
|
| 620 |
+
type="filepath"
|
| 621 |
+
)
|
| 622 |
+
|
| 623 |
+
with gr.Accordion("Quality Test (Developer)", open=False):
|
| 624 |
+
test_output = gr.Textbox(
|
| 625 |
+
label="Test Results",
|
| 626 |
+
lines=20,
|
| 627 |
+
max_lines=30,
|
| 628 |
+
interactive=False
|
| 629 |
+
)
|
| 630 |
+
run_test_btn = gr.Button("Run Quality Regression Test", variant="secondary")
|
| 631 |
+
run_test_btn.click(fn=run_quality_tests, inputs=[use_terminology], outputs=test_output)
|
| 632 |
+
|
| 633 |
+
gr.HTML(f"""
|
| 634 |
+
<div class='disclaimer'>
|
| 635 |
+
<strong>✓ Terminology Enforcement:</strong> {len(TERMINOLOGY_EN_TO_NO)} oil & gas terms from NPD glossary
|
| 636 |
+
<br>
|
| 637 |
+
<strong>✓ Privacy & Compliance:</strong> Fine-tuned on public domain data. Local inference ensures GDPR compliance.
|
| 638 |
+
<br>
|
| 639 |
+
<strong>✓ Technical Features:</strong> Sentence-level batching prevents truncation. Post-processing ensures terminology consistency.
|
| 640 |
+
</div>
|
| 641 |
+
""")
|
| 642 |
+
|
| 643 |
+
source_lang.change(fn=update_example_buttons, inputs=[source_lang], outputs=[example_text])
|
| 644 |
+
|
| 645 |
+
translate_btn.click(
|
| 646 |
+
fn=translate,
|
| 647 |
+
inputs=[input_text, source_lang, target_lang, quality_preset, use_terminology],
|
| 648 |
+
outputs=[output_text, time_display]
|
| 649 |
+
)
|
| 650 |
+
|
| 651 |
+
swap_btn.click(
|
| 652 |
+
fn=swap_languages,
|
| 653 |
+
inputs=[source_lang, target_lang, input_text, output_text],
|
| 654 |
+
outputs=[source_lang, target_lang, input_text, output_text]
|
| 655 |
+
)
|
| 656 |
+
|
| 657 |
+
file_input.change(fn=load_file, inputs=file_input, outputs=[input_text, time_display])
|
| 658 |
+
|
| 659 |
+
demo.queue().launch()
|