aliabd commited on
Commit
41ed1ac
·
1 Parent(s): d4684bd

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +7 -7
  2. run.ipynb +1 -0
  3. run.py +41 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Blocks Js Methods 3-x
3
- emoji: 🐨
4
  colorFrom: indigo
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 4.3.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: blocks_js_methods_3-x
4
+ emoji: 🔥
5
  colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 3.50.1
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: blocks_js_methods"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "blocks = gr.Blocks()\n", "\n", "with blocks as demo:\n", " subject = gr.Textbox(placeholder=\"subject\")\n", " verb = gr.Radio([\"ate\", \"loved\", \"hated\"])\n", " object = gr.Textbox(placeholder=\"object\")\n", "\n", " with gr.Row():\n", " btn = gr.Button(\"Create sentence.\")\n", " reverse_btn = gr.Button(\"Reverse sentence.\")\n", " foo_bar_btn = gr.Button(\"Append foo\")\n", " reverse_then_to_the_server_btn = gr.Button(\n", " \"Reverse sentence and send to server.\"\n", " )\n", "\n", " def sentence_maker(w1, w2, w3):\n", " return f\"{w1} {w2} {w3}\"\n", "\n", " output1 = gr.Textbox(label=\"output 1\")\n", " output2 = gr.Textbox(label=\"verb\")\n", " output3 = gr.Textbox(label=\"verb reversed\")\n", " output4 = gr.Textbox(label=\"front end process and then send to backend\")\n", "\n", " btn.click(sentence_maker, [subject, verb, object], output1)\n", " reverse_btn.click(\n", " None, [subject, verb, object], output2, _js=\"(s, v, o) => o + ' ' + v + ' ' + s\"\n", " )\n", " verb.change(lambda x: x, verb, output3, _js=\"(x) => [...x].reverse().join('')\")\n", " foo_bar_btn.click(None, [], subject, _js=\"(x) => x + ' foo'\")\n", "\n", " reverse_then_to_the_server_btn.click(\n", " sentence_maker,\n", " [subject, verb, object],\n", " output4,\n", " _js=\"(s, v, o) => [s, v, o].map(x => [...x].reverse().join(''))\",\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if __name__ == "__main__":
41
+ demo.launch()