Spaces:
Sleeping
Sleeping
Commit ·
f23e179
1
Parent(s): 1a67137
Update app.py
Browse files
app.py
CHANGED
|
@@ -289,21 +289,30 @@ PREDEFINED = [
|
|
| 289 |
]
|
| 290 |
|
| 291 |
# ---------- Reply functions compatible with ChatInterface ----------
|
| 292 |
-
# ChatInterface expects a function: (message, history) -> (reply, history)
|
| 293 |
def reply_no_attn(message, history):
|
| 294 |
if not message or not str(message).strip():
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
def reply_attn(message, history):
|
| 299 |
if not message or not str(message).strip():
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
-
# ---------- Build UI: ChatInterface side-by-side inside Blocks ----------
|
| 304 |
with gr.Blocks() as demo:
|
| 305 |
gr.Markdown("## Ubuntu Chatbot Comparison — No Attention (left) vs Attention (right)")
|
| 306 |
-
gr.Markdown("Use dropdown to quickly
|
| 307 |
|
| 308 |
with gr.Row():
|
| 309 |
# Left column: ChatInterface + dropdown
|
|
@@ -311,18 +320,15 @@ with gr.Blocks() as demo:
|
|
| 311 |
gr.Markdown("### No Attention Model")
|
| 312 |
chat_left = gr.ChatInterface(fn=reply_no_attn, title="No Attention", description="Clear button is on the chat box")
|
| 313 |
dd_left = gr.Dropdown(choices=PREDEFINED, label="Quick prompts (left)", interactive=True)
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
dd_left.change(fn=set_input_left, inputs=dd_left, outputs=chat_left.input_components[0])
|
| 317 |
|
| 318 |
# Right column: ChatInterface + dropdown
|
| 319 |
with gr.Column(scale=1):
|
| 320 |
gr.Markdown("### With Attention Model")
|
| 321 |
chat_right = gr.ChatInterface(fn=reply_attn, title="With Attention", description="Clear button is on the chat box")
|
| 322 |
dd_right = gr.Dropdown(choices=PREDEFINED, label="Quick prompts (right)", interactive=True)
|
| 323 |
-
|
| 324 |
-
return gr.update(value=selected)
|
| 325 |
-
dd_right.change(fn=set_input_right, inputs=dd_right, outputs=chat_right.input_components[0])
|
| 326 |
|
| 327 |
if __name__ == "__main__":
|
| 328 |
-
demo.launch()
|
|
|
|
| 289 |
]
|
| 290 |
|
| 291 |
# ---------- Reply functions compatible with ChatInterface ----------
|
|
|
|
| 292 |
def reply_no_attn(message, history):
|
| 293 |
if not message or not str(message).strip():
|
| 294 |
+
bot_reply = "Please enter a question."
|
| 295 |
+
else:
|
| 296 |
+
bot_reply = generate_reply_no_attn(message)
|
| 297 |
+
if history is None:
|
| 298 |
+
history = []
|
| 299 |
+
history = history + [(message, bot_reply)]
|
| 300 |
+
return bot_reply, history
|
| 301 |
|
| 302 |
def reply_attn(message, history):
|
| 303 |
if not message or not str(message).strip():
|
| 304 |
+
bot_reply = "Please enter a question."
|
| 305 |
+
else:
|
| 306 |
+
bot_reply = generate_reply_attn(message)
|
| 307 |
+
if history is None:
|
| 308 |
+
history = []
|
| 309 |
+
history = history + [(message, bot_reply)]
|
| 310 |
+
return bot_reply, history
|
| 311 |
+
|
| 312 |
|
|
|
|
| 313 |
with gr.Blocks() as demo:
|
| 314 |
gr.Markdown("## Ubuntu Chatbot Comparison — No Attention (left) vs Attention (right)")
|
| 315 |
+
gr.Markdown("Use dropdown to quickly submit predefined prompts. Each chat keeps its own history. Clear button is built in per chat.")
|
| 316 |
|
| 317 |
with gr.Row():
|
| 318 |
# Left column: ChatInterface + dropdown
|
|
|
|
| 320 |
gr.Markdown("### No Attention Model")
|
| 321 |
chat_left = gr.ChatInterface(fn=reply_no_attn, title="No Attention", description="Clear button is on the chat box")
|
| 322 |
dd_left = gr.Dropdown(choices=PREDEFINED, label="Quick prompts (left)", interactive=True)
|
| 323 |
+
# CALL the same reply function and output to the ChatInterface component
|
| 324 |
+
dd_left.select(fn=reply_no_attn, inputs=[dd_left, chat_left], outputs=[chat_left])
|
|
|
|
| 325 |
|
| 326 |
# Right column: ChatInterface + dropdown
|
| 327 |
with gr.Column(scale=1):
|
| 328 |
gr.Markdown("### With Attention Model")
|
| 329 |
chat_right = gr.ChatInterface(fn=reply_attn, title="With Attention", description="Clear button is on the chat box")
|
| 330 |
dd_right = gr.Dropdown(choices=PREDEFINED, label="Quick prompts (right)", interactive=True)
|
| 331 |
+
dd_right.select(fn=reply_attn, inputs=[dd_right, chat_right], outputs=[chat_right])
|
|
|
|
|
|
|
| 332 |
|
| 333 |
if __name__ == "__main__":
|
| 334 |
+
demo.launch()
|