Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
| 4 |
-
from transformers import T5Tokenizer, T5ForConditionalGeneration, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForCausalLM, AutoModel, pipeline
|
|
|
|
| 5 |
import languagecodes
|
| 6 |
import requests, os
|
| 7 |
import polars as pl
|
| 8 |
|
| 9 |
-
|
| 10 |
favourite_langs = {"German": "de", "Romanian": "ro", "English": "en", "-----": "-----"}
|
| 11 |
df = pl.read_parquet("isolanguages.parquet")
|
| 12 |
non_empty_isos = df.slice(1).filter(pl.col("ISO639-1") != "").rows()
|
|
@@ -444,18 +445,20 @@ def create_interface():
|
|
| 444 |
with gr.Row():
|
| 445 |
s_language = gr.Dropdown(choices=options, value = options[0], label="Source language", interactive=True)
|
| 446 |
t_language = gr.Dropdown(choices=options, value = options[1], label="Target language", interactive=True)
|
| 447 |
-
|
| 448 |
-
|
| 449 |
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
| 452 |
|
| 453 |
translated_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, show_copy_button=True)
|
| 454 |
message_text = gr.Textbox(label="Messages:", placeholder="Display field for status and error messages", interactive=False,
|
| 455 |
value=f'Default translation settings: from {s_language.value} to {t_language.value} with {model_name.value}.')
|
| 456 |
allmodels = gr.HTML(label="Model links:", value=', '.join([f'<a href="https://huggingface.co/{model}">{model}</a>' for model in models]))
|
| 457 |
-
|
| 458 |
-
|
| 459 |
fn=translate_text,
|
| 460 |
inputs=[input_text, s_language, t_language, model_name],
|
| 461 |
outputs=[translated_text, message_text]
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
| 4 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForCausalLM, AutoModel, pipeline
|
| 5 |
+
from transformers import logging as hflogging
|
| 6 |
import languagecodes
|
| 7 |
import requests, os
|
| 8 |
import polars as pl
|
| 9 |
|
| 10 |
+
hflogging.set_verbosity_error()
|
| 11 |
favourite_langs = {"German": "de", "Romanian": "ro", "English": "en", "-----": "-----"}
|
| 12 |
df = pl.read_parquet("isolanguages.parquet")
|
| 13 |
non_empty_isos = df.slice(1).filter(pl.col("ISO639-1") != "").rows()
|
|
|
|
| 445 |
with gr.Row():
|
| 446 |
s_language = gr.Dropdown(choices=options, value = options[0], label="Source language", interactive=True)
|
| 447 |
t_language = gr.Dropdown(choices=options, value = options[1], label="Target language", interactive=True)
|
| 448 |
+
swap_btn = gr.Button("Swap Languages", size="md")
|
| 449 |
+
swap_btn.click(fn=swap_languages, inputs=[s_language, t_language], outputs=[s_language, t_language], api_name=False, show_api=False)
|
| 450 |
|
| 451 |
+
with gr.Row():
|
| 452 |
+
model_name = gr.Dropdown(choices=models, label=f"Select a model. Default is {models[0]}.", value = models[0], interactive=True, scale=2)
|
| 453 |
+
model_infobtn = gr.Button("Model Info")
|
| 454 |
+
translate_btn = gr.Button("Translate")
|
| 455 |
|
| 456 |
translated_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, show_copy_button=True)
|
| 457 |
message_text = gr.Textbox(label="Messages:", placeholder="Display field for status and error messages", interactive=False,
|
| 458 |
value=f'Default translation settings: from {s_language.value} to {t_language.value} with {model_name.value}.')
|
| 459 |
allmodels = gr.HTML(label="Model links:", value=', '.join([f'<a href="https://huggingface.co/{model}">{model}</a>' for model in models]))
|
| 460 |
+
model_info = gr.Markdown(label="Model info:", value=requests.get(f'https://huggingface.co/{model_name}/raw/main/README.md'))
|
| 461 |
+
translate_btn.click(
|
| 462 |
fn=translate_text,
|
| 463 |
inputs=[input_text, s_language, t_language, model_name],
|
| 464 |
outputs=[translated_text, message_text]
|