Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,15 @@ STYLE = """
|
|
| 14 |
.custom-btn:hover {
|
| 15 |
background: rgb(243 244 246) !important;
|
| 16 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
#prompt-txt > label > span {
|
| 18 |
display: none !important;
|
| 19 |
}
|
|
@@ -133,11 +142,29 @@ function() {
|
|
| 133 |
if(history.length == 0) {
|
| 134 |
document.querySelector("#initial-popup").classList.remove('hide');
|
| 135 |
}
|
| 136 |
-
|
| 137 |
return [history, local_data];
|
| 138 |
}
|
| 139 |
"""
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
def add_pingpong(idx, ld, ping):
|
| 142 |
res = [
|
| 143 |
GradioAlpacaChatPPManager.from_json(json.dumps(ppm))
|
|
@@ -151,25 +178,25 @@ def add_pingpong(idx, ld, ping):
|
|
| 151 |
def channel_num(btn_title):
|
| 152 |
choice = 0
|
| 153 |
|
| 154 |
-
if
|
| 155 |
choice = 0
|
| 156 |
-
elif
|
| 157 |
choice = 1
|
| 158 |
-
elif
|
| 159 |
choice = 2
|
| 160 |
-
elif
|
| 161 |
choice = 3
|
| 162 |
-
elif
|
| 163 |
choice = 4
|
| 164 |
-
elif
|
| 165 |
choice = 5
|
| 166 |
-
elif
|
| 167 |
choice = 6
|
| 168 |
-
elif
|
| 169 |
choice = 7
|
| 170 |
-
elif
|
| 171 |
choice = 8
|
| 172 |
-
elif
|
| 173 |
choice = 9
|
| 174 |
|
| 175 |
return choice
|
|
@@ -182,7 +209,11 @@ def set_chatbot(btn, ld):
|
|
| 182 |
for ppm_str in ld
|
| 183 |
]
|
| 184 |
empty = len(res[choice].pingpongs) == 0
|
| 185 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
def set_example(btn):
|
| 188 |
return btn, gr.update(visible=False)
|
|
@@ -201,7 +232,7 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
|
| 201 |
|
| 202 |
with gr.Column(elem_id="left-pane"):
|
| 203 |
with gr.Accordion("Histories", elem_id="chat-history-accordion"):
|
| 204 |
-
first = gr.Button("1st Channel", elem_classes=["custom-btn"])
|
| 205 |
second = gr.Button("2nd Channel", elem_classes=["custom-btn"])
|
| 206 |
third = gr.Button("3rd Channel", elem_classes=["custom-btn"])
|
| 207 |
fourth = gr.Button("4th Channel", elem_classes=["custom-btn"])
|
|
@@ -243,7 +274,10 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
|
| 243 |
btn.click(
|
| 244 |
set_chatbot,
|
| 245 |
[btn, local_data],
|
| 246 |
-
[chatbot, idx, example_block]
|
|
|
|
|
|
|
|
|
|
| 247 |
)
|
| 248 |
|
| 249 |
ex_btns = [ex_btn1, ex_btn2, ex_btn3]
|
|
@@ -274,4 +308,4 @@ with gr.Blocks(css=STYLE, elem_id='container-col') as block:
|
|
| 274 |
_js=get_local_storage,
|
| 275 |
)
|
| 276 |
|
| 277 |
-
block.queue().launch(
|
|
|
|
| 14 |
.custom-btn:hover {
|
| 15 |
background: rgb(243 244 246) !important;
|
| 16 |
}
|
| 17 |
+
|
| 18 |
+
.custom-btn-highlight {
|
| 19 |
+
border: none !important;
|
| 20 |
+
background: rgb(243 244 246) !important;
|
| 21 |
+
box-shadow: none !important;
|
| 22 |
+
display: block !important;
|
| 23 |
+
text-align: left !important;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
#prompt-txt > label > span {
|
| 27 |
display: none !important;
|
| 28 |
}
|
|
|
|
| 142 |
if(history.length == 0) {
|
| 143 |
document.querySelector("#initial-popup").classList.remove('hide');
|
| 144 |
}
|
| 145 |
+
|
| 146 |
return [history, local_data];
|
| 147 |
}
|
| 148 |
"""
|
| 149 |
|
| 150 |
+
update_left_btns_state = """
|
| 151 |
+
(v)=>{
|
| 152 |
+
document.querySelector('.custom-btn-highlight').classList.add('custom-btn');
|
| 153 |
+
document.querySelector('.custom-btn-highlight').classList.remove('custom-btn-highlight');
|
| 154 |
+
|
| 155 |
+
const elements = document.querySelectorAll(".custom-btn");
|
| 156 |
+
|
| 157 |
+
for(var i=0; i < elements.length; i++) {
|
| 158 |
+
const element = elements[i];
|
| 159 |
+
if(element.textContent == v) {
|
| 160 |
+
console.log(v);
|
| 161 |
+
element.classList.add('custom-btn-highlight');
|
| 162 |
+
element.classList.remove('custom-btn');
|
| 163 |
+
break;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
}"""
|
| 167 |
+
|
| 168 |
def add_pingpong(idx, ld, ping):
|
| 169 |
res = [
|
| 170 |
GradioAlpacaChatPPManager.from_json(json.dumps(ppm))
|
|
|
|
| 178 |
def channel_num(btn_title):
|
| 179 |
choice = 0
|
| 180 |
|
| 181 |
+
if btn_title == "1st Channel":
|
| 182 |
choice = 0
|
| 183 |
+
elif btn_title == "2nd Channel":
|
| 184 |
choice = 1
|
| 185 |
+
elif btn_title == "3rd Channel":
|
| 186 |
choice = 2
|
| 187 |
+
elif btn_title == "4th Channel":
|
| 188 |
choice = 3
|
| 189 |
+
elif btn_title == "5th Channel":
|
| 190 |
choice = 4
|
| 191 |
+
elif btn_title == "6th Channel":
|
| 192 |
choice = 5
|
| 193 |
+
elif btn_title == "7th Channel":
|
| 194 |
choice = 6
|
| 195 |
+
elif btn_title == "8th Channel":
|
| 196 |
choice = 7
|
| 197 |
+
elif btn_title == "9th Channel":
|
| 198 |
choice = 8
|
| 199 |
+
elif btn_title == "10th Channel":
|
| 200 |
choice = 9
|
| 201 |
|
| 202 |
return choice
|
|
|
|
| 209 |
for ppm_str in ld
|
| 210 |
]
|
| 211 |
empty = len(res[choice].pingpongs) == 0
|
| 212 |
+
return (
|
| 213 |
+
res[choice].build_uis(),
|
| 214 |
+
choice,
|
| 215 |
+
gr.update(visible=empty)
|
| 216 |
+
)
|
| 217 |
|
| 218 |
def set_example(btn):
|
| 219 |
return btn, gr.update(visible=False)
|
|
|
|
| 232 |
|
| 233 |
with gr.Column(elem_id="left-pane"):
|
| 234 |
with gr.Accordion("Histories", elem_id="chat-history-accordion"):
|
| 235 |
+
first = gr.Button("1st Channel", elem_classes=["custom-btn-highlight"])
|
| 236 |
second = gr.Button("2nd Channel", elem_classes=["custom-btn"])
|
| 237 |
third = gr.Button("3rd Channel", elem_classes=["custom-btn"])
|
| 238 |
fourth = gr.Button("4th Channel", elem_classes=["custom-btn"])
|
|
|
|
| 274 |
btn.click(
|
| 275 |
set_chatbot,
|
| 276 |
[btn, local_data],
|
| 277 |
+
[chatbot, idx, example_block]
|
| 278 |
+
).then(
|
| 279 |
+
None, btn, None,
|
| 280 |
+
_js=update_left_btns_state
|
| 281 |
)
|
| 282 |
|
| 283 |
ex_btns = [ex_btn1, ex_btn2, ex_btn3]
|
|
|
|
| 308 |
_js=get_local_storage,
|
| 309 |
)
|
| 310 |
|
| 311 |
+
block.queue().launch(debug=True)
|