Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- requirements.txt +2 -2
- run.ipynb +1 -1
- run.py +10 -1
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
gradio-client @ git+https://github.com/gradio-app/gradio@
|
2 |
-
https://gradio-pypi-previews.s3.amazonaws.com/
|
|
|
1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@3e4e0de51a2ece9a1cab70a69c065bda685569e8#subdirectory=client/python
|
2 |
+
https://gradio-pypi-previews.s3.amazonaws.com/3e4e0de51a2ece9a1cab70a69c065bda685569e8/gradio-5.9.1-py3-none-any.whl
|
run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: browserstate"]}, {"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 random\n", "import string\n", "import gradio as gr\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Your Username and Password will get saved in the browser's local storage. \"\n", " \"If you refresh the page, the values will be retained.\")\n", " username = gr.Textbox(label=\"Username\")\n", " password = gr.Textbox(label=\"Password\", type=\"password\")\n", " btn = gr.Button(\"Generate Randomly\")\n", " local_storage = gr.BrowserState([\"\", \"\"])\n", "\n", " @btn.click(outputs=[username, password])\n", " def generate_randomly():\n", " u = \"\".join(random.choices(string.ascii_letters + string.digits, k=10))\n", " p = \"\".join(random.choices(string.ascii_letters + string.digits, k=10))\n", " return u, p\n", "\n", " @demo.load(inputs=[local_storage], outputs=[username, password])\n", " def load_from_local_storage(saved_values):\n", " print(\"loading from local storage\", saved_values)\n", " return saved_values[0], saved_values[1]\n", "\n", " @gr.on([username.change, password.change], inputs=[username, password], outputs=[local_storage])\n", " def save_to_local_storage(username, password):\n", " return [username, password]\n", "\n", "demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: browserstate"]}, {"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 random\n", "import string\n", "import gradio as gr\n", "import time\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Your Username and Password will get saved in the browser's local storage. \"\n", " \"If you refresh the page, the values will be retained.\")\n", " username = gr.Textbox(label=\"Username\")\n", " password = gr.Textbox(label=\"Password\", type=\"password\")\n", " btn = gr.Button(\"Generate Randomly\")\n", " local_storage = gr.BrowserState([\"\", \"\"])\n", " saved_message = gr.Markdown(\"\u2705 Saved to local storage\", visible=False)\n", "\n", " @btn.click(outputs=[username, password])\n", " def generate_randomly():\n", " u = \"\".join(random.choices(string.ascii_letters + string.digits, k=10))\n", " p = \"\".join(random.choices(string.ascii_letters + string.digits, k=10))\n", " return u, p\n", "\n", " @demo.load(inputs=[local_storage], outputs=[username, password])\n", " def load_from_local_storage(saved_values):\n", " print(\"loading from local storage\", saved_values)\n", " return saved_values[0], saved_values[1]\n", "\n", " @gr.on([username.change, password.change], inputs=[username, password], outputs=[local_storage])\n", " def save_to_local_storage(username, password):\n", " return [username, password]\n", "\n", " @gr.on(local_storage.change, outputs=[saved_message])\n", " def show_saved_message():\n", " timestamp = time.strftime(\"%I:%M:%S %p\")\n", " return gr.Markdown(\n", " f\"\u2705 Saved to local storage at {timestamp}\",\n", " visible=True\n", " )\n", "\n", "demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import random
|
2 |
import string
|
3 |
import gradio as gr
|
4 |
-
|
5 |
with gr.Blocks() as demo:
|
6 |
gr.Markdown("Your Username and Password will get saved in the browser's local storage. "
|
7 |
"If you refresh the page, the values will be retained.")
|
@@ -9,6 +9,7 @@ with gr.Blocks() as demo:
|
|
9 |
password = gr.Textbox(label="Password", type="password")
|
10 |
btn = gr.Button("Generate Randomly")
|
11 |
local_storage = gr.BrowserState(["", ""])
|
|
|
12 |
|
13 |
@btn.click(outputs=[username, password])
|
14 |
def generate_randomly():
|
@@ -25,4 +26,12 @@ with gr.Blocks() as demo:
|
|
25 |
def save_to_local_storage(username, password):
|
26 |
return [username, password]
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
demo.launch()
|
|
|
1 |
import random
|
2 |
import string
|
3 |
import gradio as gr
|
4 |
+
import time
|
5 |
with gr.Blocks() as demo:
|
6 |
gr.Markdown("Your Username and Password will get saved in the browser's local storage. "
|
7 |
"If you refresh the page, the values will be retained.")
|
|
|
9 |
password = gr.Textbox(label="Password", type="password")
|
10 |
btn = gr.Button("Generate Randomly")
|
11 |
local_storage = gr.BrowserState(["", ""])
|
12 |
+
saved_message = gr.Markdown("✅ Saved to local storage", visible=False)
|
13 |
|
14 |
@btn.click(outputs=[username, password])
|
15 |
def generate_randomly():
|
|
|
26 |
def save_to_local_storage(username, password):
|
27 |
return [username, password]
|
28 |
|
29 |
+
@gr.on(local_storage.change, outputs=[saved_message])
|
30 |
+
def show_saved_message():
|
31 |
+
timestamp = time.strftime("%I:%M:%S %p")
|
32 |
+
return gr.Markdown(
|
33 |
+
f"✅ Saved to local storage at {timestamp}",
|
34 |
+
visible=True
|
35 |
+
)
|
36 |
+
|
37 |
demo.launch()
|