bkoo commited on
Commit
0ca1589
·
verified ·
1 Parent(s): 3fbe79b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -26
app.py CHANGED
@@ -1,28 +1,25 @@
1
- import random
2
- import gradio as gr
3
-
4
- def chat(message, history):
5
- history = history or []
6
- message = message.lower()
7
-
8
- if message.startswith('how many'):
9
- response= str(random.randint(1,10))
10
- elif message.startswith("how"):
11
- response = random.choice(["Great", "Good", "Fine", "Okay", "Alright"])
12
- elif message.startswith("where"):
13
- response = random.choice(["In the house", "In the car", "In the forest", "In the mountains"])
14
- else:
15
- response = "I don't know."
16
- history.append((message, response))
17
- return history, history
18
-
19
- chatbot = gr.Chatbot()
20
-
21
- demo = gr.Interface(
22
- chat,
23
- ["text", "state"],
24
- [chatbot, "state"],
25
- allow_flagging="never",
26
- )
27
 
28
  demo.launch()
 
1
+ import gradio as gr
2
+
3
+
4
+ from transformers import pipeline
5
+
6
+ pipe = pipeline("translation", model="t5-base")
7
+
8
+
9
+ def translate(text):
10
+ return pipe(text)[0]["translation_text"]
11
+
12
+
13
+ with gr.Blocks() as demo:
14
+ with gr.Row():
15
+ with gr.Column():
16
+ english = gr.Textbox(label="English text")
17
+ translate_btn = gr.Button(value="Translate")
18
+ with gr.Column():
19
+ german = gr.Textbox(label="German text")
20
+
21
+ translate_btn.click(translate, inputs=english, outputs=german)
22
+ examples = gr.Examples(examples= ["I went to the supermarket yesterday.", "Heen is a good swimmer"],
23
+ inputs=[english])
 
 
 
24
 
25
  demo.launch()