Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,18 +62,28 @@ function() {
|
|
| 62 |
globalThis.getStorage = (key, value)=>{
|
| 63 |
return JSON.parse(localStorage.getItem(key));
|
| 64 |
}
|
| 65 |
-
|
| 66 |
const history = [];
|
| 67 |
-
console.log(1);
|
| 68 |
if(local_data) {
|
| 69 |
-
console.log(2);
|
| 70 |
console.log(local_data);
|
| 71 |
local_data[0].pingpongs.forEach(element =>
|
| 72 |
history.push([element.ping, element.pong])
|
| 73 |
);
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
console.log(history);
|
| 76 |
-
return [
|
| 77 |
}
|
| 78 |
"""
|
| 79 |
|
|
@@ -106,42 +116,9 @@ def set_chatbot(btn, ld):
|
|
| 106 |
]
|
| 107 |
return res[choice].build_uis(), choice
|
| 108 |
|
| 109 |
-
def initialize(local_data):
|
| 110 |
-
if local_data is None:
|
| 111 |
-
list_conv = [
|
| 112 |
-
GradioAlpacaChatPPManager()
|
| 113 |
-
for _ in range(5)
|
| 114 |
-
]
|
| 115 |
-
local_data = str(list_conv)
|
| 116 |
-
|
| 117 |
-
return local_data
|
| 118 |
-
|
| 119 |
-
def initialize_t(ld):
|
| 120 |
-
print(ld)
|
| 121 |
-
|
| 122 |
-
if ld == {} or id is None:
|
| 123 |
-
list_conv = [
|
| 124 |
-
GradioAlpacaChatPPManager()
|
| 125 |
-
for _ in range(5)
|
| 126 |
-
]
|
| 127 |
-
local_data = str(list_conv)
|
| 128 |
-
else:
|
| 129 |
-
list_conv = [
|
| 130 |
-
GradioAlpacaChatPPManager.from_json(json.dumps(ppm))
|
| 131 |
-
for ppm in ld
|
| 132 |
-
]
|
| 133 |
-
local_data = str(list_conv)
|
| 134 |
-
|
| 135 |
-
return list_conv[0].build_uis(), local_data
|
| 136 |
-
|
| 137 |
with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
| 138 |
idx = gr.State(0)
|
| 139 |
-
|
| 140 |
-
local_data = gr.JSON(
|
| 141 |
-
{},
|
| 142 |
-
label="Local Storage",
|
| 143 |
-
visible=False
|
| 144 |
-
)
|
| 145 |
|
| 146 |
with gr.Row():
|
| 147 |
with gr.Column(scale=1, min_width=180):
|
|
@@ -162,61 +139,15 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
|
| 162 |
elem_id="prompt-txt"
|
| 163 |
)
|
| 164 |
|
| 165 |
-
first
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
[chatbot, idx]
|
| 173 |
-
)
|
| 174 |
-
|
| 175 |
-
second.click(
|
| 176 |
-
initialize,
|
| 177 |
-
local_data,
|
| 178 |
-
local_data
|
| 179 |
-
).then(
|
| 180 |
-
set_chatbot,
|
| 181 |
-
[second, local_data],
|
| 182 |
-
[chatbot, idx]
|
| 183 |
-
)
|
| 184 |
-
|
| 185 |
-
third.click(
|
| 186 |
-
initialize,
|
| 187 |
-
local_data,
|
| 188 |
-
local_data
|
| 189 |
-
).then(
|
| 190 |
-
set_chatbot,
|
| 191 |
-
[third, local_data],
|
| 192 |
-
[chatbot, idx]
|
| 193 |
-
)
|
| 194 |
|
| 195 |
-
fourth.click(
|
| 196 |
-
initialize,
|
| 197 |
-
local_data,
|
| 198 |
-
local_data
|
| 199 |
-
).then(
|
| 200 |
-
set_chatbot,
|
| 201 |
-
[fourth, local_data],
|
| 202 |
-
[chatbot, idx]
|
| 203 |
-
)
|
| 204 |
-
|
| 205 |
-
fifth.click(
|
| 206 |
-
initialize,
|
| 207 |
-
local_data,
|
| 208 |
-
local_data
|
| 209 |
-
).then(
|
| 210 |
-
set_chatbot,
|
| 211 |
-
[fifth, local_data],
|
| 212 |
-
[chatbot, idx]
|
| 213 |
-
)
|
| 214 |
-
|
| 215 |
instruction_txtbox.submit(
|
| 216 |
-
initialize,
|
| 217 |
-
local_data,
|
| 218 |
-
local_data
|
| 219 |
-
).then(
|
| 220 |
add_pingpong,
|
| 221 |
[idx, local_data, instruction_txtbox],
|
| 222 |
[chatbot, local_data]
|
|
@@ -228,7 +159,7 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
|
| 228 |
block.load(
|
| 229 |
None,
|
| 230 |
inputs=None,
|
| 231 |
-
outputs=[
|
| 232 |
_js=get_local_storage,
|
| 233 |
)
|
| 234 |
|
|
|
|
| 62 |
globalThis.getStorage = (key, value)=>{
|
| 63 |
return JSON.parse(localStorage.getItem(key));
|
| 64 |
}
|
| 65 |
+
var local_data = getStorage('local_data');
|
| 66 |
const history = [];
|
|
|
|
| 67 |
if(local_data) {
|
|
|
|
| 68 |
console.log(local_data);
|
| 69 |
local_data[0].pingpongs.forEach(element =>
|
| 70 |
history.push([element.ping, element.pong])
|
| 71 |
);
|
| 72 |
}
|
| 73 |
+
else {
|
| 74 |
+
local_data = [
|
| 75 |
+
{'ctx': '', 'pingpongs':[]},
|
| 76 |
+
{'ctx': '', 'pingpongs':[]},
|
| 77 |
+
{'ctx': '', 'pingpongs':[]},
|
| 78 |
+
{'ctx': '', 'pingpongs':[]},
|
| 79 |
+
{'ctx': '', 'pingpongs':[]},
|
| 80 |
+
];
|
| 81 |
+
local_data[0].pingpongs.forEach(element =>
|
| 82 |
+
history.push([element.ping, element.pong])
|
| 83 |
+
);
|
| 84 |
+
}
|
| 85 |
console.log(history);
|
| 86 |
+
return [history, local_data];
|
| 87 |
}
|
| 88 |
"""
|
| 89 |
|
|
|
|
| 116 |
]
|
| 117 |
return res[choice].build_uis(), choice
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
| 120 |
idx = gr.State(0)
|
| 121 |
+
local_data = gr.JSON({},visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
with gr.Row():
|
| 124 |
with gr.Column(scale=1, min_width=180):
|
|
|
|
| 139 |
elem_id="prompt-txt"
|
| 140 |
)
|
| 141 |
|
| 142 |
+
btns = [first, second, third, fourth, fifth]
|
| 143 |
+
for btn in btns:
|
| 144 |
+
btn.click(
|
| 145 |
+
set_chatbot,
|
| 146 |
+
[btn, local_data],
|
| 147 |
+
[chatbot, idx]
|
| 148 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
instruction_txtbox.submit(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
add_pingpong,
|
| 152 |
[idx, local_data, instruction_txtbox],
|
| 153 |
[chatbot, local_data]
|
|
|
|
| 159 |
block.load(
|
| 160 |
None,
|
| 161 |
inputs=None,
|
| 162 |
+
outputs=[chatbot, local_data],
|
| 163 |
_js=get_local_storage,
|
| 164 |
)
|
| 165 |
|