Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.5.0
|
8 |
-
app_file:
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
|
2 |
---
|
3 |
+
title: browserstate_main
|
4 |
+
emoji: 🔥
|
5 |
+
colorFrom: indigo
|
6 |
+
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 5.5.0
|
9 |
+
app_file: run.py
|
10 |
pinned: false
|
11 |
+
hf_oauth: true
|
12 |
---
|
|
|
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@fc06fe41f015678a0545f4e5c99f6ae2704f0031#subdirectory=client/python
|
2 |
+
https://gradio-pypi-previews.s3.amazonaws.com/fc06fe41f015678a0545f4e5c99f6ae2704f0031/gradio-5.5.0-py3-none-any.whl
|
run.ipynb
ADDED
@@ -0,0 +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}
|
run.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.")
|
8 |
+
username = gr.Textbox(label="Username")
|
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():
|
15 |
+
u = "".join(random.choices(string.ascii_letters + string.digits, k=10))
|
16 |
+
p = "".join(random.choices(string.ascii_letters + string.digits, k=10))
|
17 |
+
return u, p
|
18 |
+
|
19 |
+
@demo.load(inputs=[local_storage], outputs=[username, password])
|
20 |
+
def load_from_local_storage(saved_values):
|
21 |
+
print("loading from local storage", saved_values)
|
22 |
+
return saved_values[0], saved_values[1]
|
23 |
+
|
24 |
+
@gr.on([username.change, password.change], inputs=[username, password], outputs=[local_storage])
|
25 |
+
def save_to_local_storage(username, password):
|
26 |
+
return [username, password]
|
27 |
+
|
28 |
+
demo.launch()
|