Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,10 +4,6 @@ from pingpong import PingPong
|
|
| 4 |
from pingpong.gradio import GradioAlpacaChatPPManager
|
| 5 |
|
| 6 |
STYLE = """
|
| 7 |
-
#container-col {
|
| 8 |
-
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
.custom-btn {
|
| 12 |
border: none !important;
|
| 13 |
background: none !important;
|
|
@@ -117,13 +113,14 @@ function() {
|
|
| 117 |
globalThis.getStorage = (key, value)=>{
|
| 118 |
return JSON.parse(localStorage.getItem(key));
|
| 119 |
}
|
|
|
|
| 120 |
var local_data = getStorage('local_data');
|
| 121 |
-
|
|
|
|
| 122 |
if(local_data) {
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
);
|
| 127 |
}
|
| 128 |
else {
|
| 129 |
local_data = [
|
|
@@ -131,16 +128,14 @@ function() {
|
|
| 131 |
{'ctx': '', 'pingpongs':[]},
|
| 132 |
{'ctx': '', 'pingpongs':[]},
|
| 133 |
{'ctx': '', 'pingpongs':[]},
|
| 134 |
-
{'ctx': '', 'pingpongs':[]}
|
| 135 |
];
|
| 136 |
-
local_data
|
| 137 |
-
history.push([element.ping, element.pong])
|
| 138 |
-
);
|
| 139 |
}
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
|
| 145 |
return [history, local_data];
|
| 146 |
}
|
|
@@ -154,7 +149,7 @@ def add_pingpong(idx, ld, ping):
|
|
| 154 |
|
| 155 |
ppm = res[idx]
|
| 156 |
ppm.add_pingpong(PingPong(ping, "dang!!!!!!!"))
|
| 157 |
-
return ppm.build_uis(), str(res)
|
| 158 |
|
| 159 |
def set_chatbot(btn, ld):
|
| 160 |
choice = 0
|
|
@@ -179,6 +174,10 @@ def set_chatbot(btn, ld):
|
|
| 179 |
def set_example(btn):
|
| 180 |
return btn, gr.update(visible=False)
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
| 183 |
idx = gr.State(0)
|
| 184 |
local_data = gr.JSON({},visible=False)
|
|
@@ -235,9 +234,13 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
|
| 235 |
)
|
| 236 |
|
| 237 |
instruction_txtbox.submit(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
add_pingpong,
|
| 239 |
[idx, local_data, instruction_txtbox],
|
| 240 |
-
[chatbot, local_data
|
| 241 |
).then(
|
| 242 |
None, local_data, None,
|
| 243 |
_js="(v)=>{ setStorage('local_data',v) }"
|
|
@@ -248,6 +251,6 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
|
| 248 |
inputs=None,
|
| 249 |
outputs=[chatbot, local_data],
|
| 250 |
_js=get_local_storage,
|
| 251 |
-
)
|
| 252 |
|
| 253 |
-
block.launch(
|
|
|
|
| 4 |
from pingpong.gradio import GradioAlpacaChatPPManager
|
| 5 |
|
| 6 |
STYLE = """
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
.custom-btn {
|
| 8 |
border: none !important;
|
| 9 |
background: none !important;
|
|
|
|
| 113 |
globalThis.getStorage = (key, value)=>{
|
| 114 |
return JSON.parse(localStorage.getItem(key));
|
| 115 |
}
|
| 116 |
+
|
| 117 |
var local_data = getStorage('local_data');
|
| 118 |
+
var history = [];
|
| 119 |
+
|
| 120 |
if(local_data) {
|
| 121 |
+
local_data[0].pingpongs.forEach(element =>{
|
| 122 |
+
history.push([element.ping, element.pong]);
|
| 123 |
+
});
|
|
|
|
| 124 |
}
|
| 125 |
else {
|
| 126 |
local_data = [
|
|
|
|
| 128 |
{'ctx': '', 'pingpongs':[]},
|
| 129 |
{'ctx': '', 'pingpongs':[]},
|
| 130 |
{'ctx': '', 'pingpongs':[]},
|
| 131 |
+
{'ctx': '', 'pingpongs':[]}
|
| 132 |
];
|
| 133 |
+
setStorage('local_data', local_data);
|
|
|
|
|
|
|
| 134 |
}
|
| 135 |
|
| 136 |
+
if(history.length == 0) {
|
| 137 |
+
document.querySelector("#initial-popup").classList.remove('hide');
|
| 138 |
+
}
|
| 139 |
|
| 140 |
return [history, local_data];
|
| 141 |
}
|
|
|
|
| 149 |
|
| 150 |
ppm = res[idx]
|
| 151 |
ppm.add_pingpong(PingPong(ping, "dang!!!!!!!"))
|
| 152 |
+
return "", ppm.build_uis(), str(res)
|
| 153 |
|
| 154 |
def set_chatbot(btn, ld):
|
| 155 |
choice = 0
|
|
|
|
| 174 |
def set_example(btn):
|
| 175 |
return btn, gr.update(visible=False)
|
| 176 |
|
| 177 |
+
def set_popup_visibility(ld, example_block):
|
| 178 |
+
print(ld)
|
| 179 |
+
return example_block
|
| 180 |
+
|
| 181 |
with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
| 182 |
idx = gr.State(0)
|
| 183 |
local_data = gr.JSON({},visible=False)
|
|
|
|
| 234 |
)
|
| 235 |
|
| 236 |
instruction_txtbox.submit(
|
| 237 |
+
lambda: gr.update(visible=False),
|
| 238 |
+
None,
|
| 239 |
+
example_block
|
| 240 |
+
).then(
|
| 241 |
add_pingpong,
|
| 242 |
[idx, local_data, instruction_txtbox],
|
| 243 |
+
[instruction_txtbox, chatbot, local_data]
|
| 244 |
).then(
|
| 245 |
None, local_data, None,
|
| 246 |
_js="(v)=>{ setStorage('local_data',v) }"
|
|
|
|
| 251 |
inputs=None,
|
| 252 |
outputs=[chatbot, local_data],
|
| 253 |
_js=get_local_storage,
|
| 254 |
+
)
|
| 255 |
|
| 256 |
+
block.queue().launch(share=False)
|