MrOvkill commited on
Commit
8565ad0
1 Parent(s): 0276f1d
Files changed (3) hide show
  1. README.md +11 -3
  2. app.py +28 -0
  3. demo.ipynb +92 -0
README.md CHANGED
@@ -1,13 +1,21 @@
 
1
  ---
2
- title: SubmittableDynamicText
3
  emoji: 🦀
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.26.0
8
  app_file: app.py
9
- pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
1
+
2
  ---
3
+ title: Submittable Dynamic Text - Template
4
  emoji: 🦀
5
  colorFrom: blue
6
  colorTo: green
7
  sdk: gradio
8
  sdk_version: 4.26.0
9
  app_file: app.py
10
+ pinned: true
11
  license: mit
12
  ---
13
 
14
+ # Submittable Dynamic Text
15
+
16
+ Some of us still see the value in simple completions. To this end, we have created a Submittable Dynamic Text component ( A text box that sends a request when Shift-Enter is pressed. )
17
+
18
+ Enjoy!
19
+
20
+ `Made with <3 - Sam`
21
+
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import os
4
+
5
+ GRADIO_PORT = os.getenv("GRADIO_PORT") or 7680
6
+ GRADIO_SHARE = os.getenv("GRADIO_SHARE") or True
7
+ GRADIO_DEBUG = os.getenv("GRADIO_DEBUG") or True
8
+
9
+ SDT_PLACEHOLDER = os.getenv("SDT_PLACEHOLDER") or "Ctrl-Shift to get a response..."
10
+ SDT_LABEL = os.getenv("SDT_LABEL") or "Dyanmic Text ( Shift-Enter to send )"
11
+ SDT_LINES = os.getenv("SDT_LINES") or "\n"*16
12
+
13
+ INITIAL_STATE = {
14
+ "html": f"""
15
+ <h1>Welcome</h1>
16
+ """
17
+ }
18
+
19
+ def greeting(inpt):
20
+ return "<strong>You Said</strong>, <p>" + inpt.strip() + "</p>!\n\n"
21
+
22
+ with gr.Blocks() as dmo:
23
+ with gr.Row():
24
+ output = gr.HTML(INITIAL_STATE['html'])
25
+ with gr.Row():
26
+ inpt = gr.Textbox(SDT_LINES, placeholder=SDT_PLACEHOLDER, label=SDT_LABEL, lines=len(SDT_LINES))
27
+ inpt.submit(greeting, inputs=[inpt], outputs=[inpt])
28
+ dmo.launch(share=GRADIO_SHARE, debug=GRADIO_DEBUG, inline=True, server_port=GRADIO_PORT)
demo.ipynb ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Submittable Dynamic Text Area"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": 3,
13
+ "metadata": {},
14
+ "outputs": [
15
+ {
16
+ "name": "stdout",
17
+ "output_type": "stream",
18
+ "text": [
19
+ "Running on local URL: http://127.0.0.1:7680\n",
20
+ "Running on public URL: https://7e928ad820ac1daccd.gradio.live\n",
21
+ "\n",
22
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
23
+ ]
24
+ },
25
+ {
26
+ "data": {
27
+ "text/html": [
28
+ "<div><iframe src=\"https://7e928ad820ac1daccd.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
29
+ ],
30
+ "text/plain": [
31
+ "<IPython.core.display.HTML object>"
32
+ ]
33
+ },
34
+ "metadata": {},
35
+ "output_type": "display_data"
36
+ }
37
+ ],
38
+ "source": [
39
+ "# %load app.py\n",
40
+ "import gradio as gr\n",
41
+ "\n",
42
+ "import os\n",
43
+ "\n",
44
+ "GRADIO_PORT = os.getenv(\"GRADIO_PORT\") or 7680\n",
45
+ "GRADIO_SHARE = os.getenv(\"GRADIO_SHARE\") or True\n",
46
+ "GRADIO_DEBUG = os.getenv(\"GRADIO_DEBUG\") or True\n",
47
+ "\n",
48
+ "SDT_PLACEHOLDER = os.getenv(\"SDT_PLACEHOLDER\") or \"Ctrl-Shift to get a response...\"\n",
49
+ "SDT_LABEL = os.getenv(\"SDT_LABEL\") or \"Dyanmic Text ( Shift-Enter to send )\"\n",
50
+ "SDT_LINES = os.getenv(\"SDT_LINES\") or \"\\n\"*16\n",
51
+ "\n",
52
+ "INITIAL_STATE = {\n",
53
+ " \"html\": f\"\"\"\n",
54
+ "<h1>Welcome</h1>\n",
55
+ "\"\"\"\n",
56
+ "}\n",
57
+ "\n",
58
+ "def greeting(inpt):\n",
59
+ " return \"<strong>You Said</strong>, <p>\" + inpt.strip() + \"</p>!\\n\\n\"\n",
60
+ "\n",
61
+ "with gr.Blocks() as dmo:\n",
62
+ " with gr.Row():\n",
63
+ " output = gr.HTML(INITIAL_STATE['html'])\n",
64
+ " with gr.Row():\n",
65
+ " inpt = gr.Textbox(SDT_LINES, placeholder=SDT_PLACEHOLDER, label=SDT_LABEL, lines=len(SDT_LINES))\n",
66
+ " inpt.submit(greeting, inputs=[inpt], outputs=[inpt])\n",
67
+ " dmo.launch(share=GRADIO_SHARE, debug=GRADIO_DEBUG, inline=True, server_port=GRADIO_PORT)"
68
+ ]
69
+ }
70
+ ],
71
+ "metadata": {
72
+ "kernelspec": {
73
+ "display_name": "Python 3",
74
+ "language": "python",
75
+ "name": "python3"
76
+ },
77
+ "language_info": {
78
+ "codemirror_mode": {
79
+ "name": "ipython",
80
+ "version": 3
81
+ },
82
+ "file_extension": ".py",
83
+ "mimetype": "text/x-python",
84
+ "name": "python",
85
+ "nbconvert_exporter": "python",
86
+ "pygments_lexer": "ipython3",
87
+ "version": "3.11.9"
88
+ }
89
+ },
90
+ "nbformat": 4,
91
+ "nbformat_minor": 2
92
+ }