Spaces:
Runtime error
Runtime error
test-app
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
blocks = gr.Blocks()
|
4 |
+
|
5 |
+
with blocks as demo:
|
6 |
+
subject = gr.Textbox(placeholder="subject")
|
7 |
+
verb = gr.Radio(["ate", "loved", "hated"])
|
8 |
+
object = gr.Textbox(placeholder="object")
|
9 |
+
|
10 |
+
with gr.Row():
|
11 |
+
btn = gr.Button("Create sentence.")
|
12 |
+
reverse_btn = gr.Button("Reverse sentence.")
|
13 |
+
foo_bar_btn = gr.Button("Append foo")
|
14 |
+
reverse_then_to_the_server_btn = gr.Button(
|
15 |
+
"Reverse sentence and send to server."
|
16 |
+
)
|
17 |
+
|
18 |
+
def sentence_maker(w1, w2, w3):
|
19 |
+
return f"{w1} {w2} {w3}"
|
20 |
+
|
21 |
+
output1 = gr.Textbox(label="output 1")
|
22 |
+
output2 = gr.Textbox(label="verb")
|
23 |
+
output3 = gr.Textbox(label="verb reversed")
|
24 |
+
output4 = gr.Textbox(label="front end process and then send to backend")
|
25 |
+
|
26 |
+
btn.click(sentence_maker, [subject, verb, object], output1)
|
27 |
+
reverse_btn.click(
|
28 |
+
None, [subject, verb, object], output2, js="(s, v, o) => o + ' ' + v + ' ' + s"
|
29 |
+
)
|
30 |
+
verb.change(lambda x: x, verb, output3, js="(x) => [...x].reverse().join('')")
|
31 |
+
foo_bar_btn.click(None, [], subject, js="(x) => x + ' foo'")
|
32 |
+
|
33 |
+
reverse_then_to_the_server_btn.click(
|
34 |
+
sentence_maker,
|
35 |
+
[subject, verb, object],
|
36 |
+
output4,
|
37 |
+
js="(s, v, o) => [s, v, o].map(x => [...x].reverse().join(''))",
|
38 |
+
)
|
39 |
+
|
40 |
+
demo.launch()
|