Spaces:
Running
Running
Duplicate from radames/gradio_window_localStorage
Browse filesCo-authored-by: Radamés Ajna <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +43 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Gradio Window LocalStorage
|
3 |
+
emoji: 🫙
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.29.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: radames/gradio_window_localStorage
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
get_local_storage = """
|
4 |
+
function() {
|
5 |
+
globalThis.setStorage = (key, value)=>{
|
6 |
+
localStorage.setItem(key, JSON.stringify(value))
|
7 |
+
}
|
8 |
+
globalThis.getStorage = (key, value)=>{
|
9 |
+
return JSON.parse(localStorage.getItem(key))
|
10 |
+
}
|
11 |
+
const text_input = getStorage('text_input')
|
12 |
+
const dropdown = getStorage('dropdown')
|
13 |
+
const local_data = getStorage('local_data')
|
14 |
+
return [text_input, dropdown, local_data];
|
15 |
+
}
|
16 |
+
"""
|
17 |
+
|
18 |
+
|
19 |
+
def predict(text_input, dropdown):
|
20 |
+
return {
|
21 |
+
"text": text_input,
|
22 |
+
"dropdown": dropdown,
|
23 |
+
"something_else": [text_input] * 3 + [dropdown],
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
with gr.Blocks() as block:
|
28 |
+
text_input = gr.Text(label="Input")
|
29 |
+
dropdown = gr.Dropdown(["first", "second", "third"], type="index")
|
30 |
+
local_data = gr.JSON({}, label="Local Storage")
|
31 |
+
|
32 |
+
dropdown.change(None, dropdown, None, _js="(v)=>{ setStorage('dropdown',v) }")
|
33 |
+
text_input.change(None, text_input, None, _js="(v)=>{ setStorage('text_input',v) }")
|
34 |
+
local_data.change(None, local_data, None, _js="(v)=>{ setStorage('local_data',v) }")
|
35 |
+
btn = gr.Button("Set New Data")
|
36 |
+
btn.click(fn=predict, inputs=[text_input, dropdown], outputs=[local_data])
|
37 |
+
block.load(
|
38 |
+
None,
|
39 |
+
inputs=None,
|
40 |
+
outputs=[text_input, dropdown, local_data],
|
41 |
+
_js=get_local_storage,
|
42 |
+
)
|
43 |
+
block.launch(debug=True)
|