claudiatang commited on
Commit
cf70c5f
1 Parent(s): 0033167

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
2
+ import gradio as gr
3
+
4
+ # Create translation function
5
+ tokenizer = AutoTokenizer.from_pretrained("claudiatang/flan-t5-base-eng-hwp")
6
+ model = AutoModelForSeq2SeqLM.from_pretrained("claudiatang/flan-t5-base-eng-hwp")
7
+
8
+ def translate_eng_hwp(eng_input):
9
+ translator = pipeline("translation", model=model, tokenizer=tokenizer)
10
+ eng_input = "translate English to Hawaiian Pidgin: " + str(eng_input)
11
+ output = translator(eng_input)
12
+ hwp_output = output[0]["translation_text"]
13
+ return hwp_output
14
+
15
+ # Create Gradio interface
16
+ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue")) as demo:
17
+ gr.HTML("""<br><h1 style="text-align:center; font-weight: bold"> English-Hawaiian Pidgin Translator 🤙 </h1>""")
18
+ with gr.Row():
19
+ with gr.Column():
20
+ english = gr.Textbox(label="English Text", placeholder="Enter English text here...")
21
+ with gr.Column():
22
+ hawaiian_pidgin = gr.Textbox(label="Hawaiian Pidgin Text", placeholder= "Hawaiian Pidgin translation will appear here.")
23
+ with gr.Row():
24
+ translate_btn = gr.Button(value="Translate", variant="primary")
25
+ translate_btn.click(translate_eng_hwp, inputs=english, outputs=hawaiian_pidgin)
26
+ examples = gr.Examples(examples=["I went shopping at Ala Moana yesterday.", "We baked a cake today."],
27
+ inputs=[english])
28
+ gr.Markdown("""For more information, check out the [model page](https://huggingface.co/claudiatang/flan-t5-base-eng-hwp).""")
29
+
30
+ demo.launch()