Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Model logic (conceptual)
|
| 6 |
+
translator = pipeline("text2text-generation", model="t5-small")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def translate(Prompt):
|
| 10 |
+
|
| 11 |
+
prompt = "translate English to French: How are you?"
|
| 12 |
+
prompt=prompt +" "+Prompt
|
| 13 |
+
result = translator(prompt, max_length=50, num_return_sequences=1 , temperature=0.7)
|
| 14 |
+
|
| 15 |
+
# Print the generated text
|
| 16 |
+
print(result[0]['generated_text'])
|
| 17 |
+
return result[0]['generated_text']
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
with gr.Row():
|
| 21 |
+
with gr.Column():
|
| 22 |
+
english = gr.Textbox(label="English text")
|
| 23 |
+
with gr.Column():
|
| 24 |
+
german = gr.Textbox(label="German text")
|
| 25 |
+
|
| 26 |
+
translate_btn = gr.Button("Translate")
|
| 27 |
+
translate_btn.click(fn=translate, inputs=english, outputs=german)
|
| 28 |
+
|
| 29 |
+
# Adding examples at the bottom
|
| 30 |
+
gr.Examples(["Hello, how are you?", "I am learning Gradio."], inputs=english)
|