Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -517,6 +517,26 @@ def send_message(message, history):
|
|
517 |
yield history + [{"role": "assistant", "content": partial}]
|
518 |
|
519 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
# Create the dashboard
|
521 |
with gr.Blocks(theme=ArtemisiaTheme(), css=custom_css) as demo:
|
522 |
# Header
|
@@ -568,6 +588,7 @@ with gr.Blocks(theme=ArtemisiaTheme(), css=custom_css) as demo:
|
|
568 |
# inputs=[chat_input, chatbot],
|
569 |
# outputs=[chatbot]
|
570 |
#).then(lambda: "", None, chat_input)
|
|
|
571 |
send_button.click(
|
572 |
lambda msg: (gr.update(value=""), msg), # clears textbox immediately
|
573 |
inputs=[chat_input],
|
@@ -587,6 +608,34 @@ with gr.Blocks(theme=ArtemisiaTheme(), css=custom_css) as demo:
|
|
587 |
inputs=[chat_input, chatbot],
|
588 |
outputs=[chatbot]
|
589 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
590 |
# JavaScript for UI enhancements
|
591 |
gr.HTML("""
|
592 |
<script>
|
|
|
517 |
yield history + [{"role": "assistant", "content": partial}]
|
518 |
|
519 |
|
520 |
+
def start_generation(message, history):
|
521 |
+
history.append({"role": "user", "content": message})
|
522 |
+
return message, history # Pass message along with updated history
|
523 |
+
|
524 |
+
|
525 |
+
def continue_generation(message, history):
|
526 |
+
if message.lower() in database:
|
527 |
+
context = random.choice(database[message.lower()])
|
528 |
+
message += " \n" + context
|
529 |
+
response_generator = wrapper.generate(message, history)
|
530 |
+
partial = ""
|
531 |
+
idx = 0
|
532 |
+
for t in response_generator:
|
533 |
+
if idx <= 3:
|
534 |
+
idx += 1
|
535 |
+
continue
|
536 |
+
partial += t
|
537 |
+
yield history + [{"role": "assistant", "content": partial}]
|
538 |
+
|
539 |
+
|
540 |
# Create the dashboard
|
541 |
with gr.Blocks(theme=ArtemisiaTheme(), css=custom_css) as demo:
|
542 |
# Header
|
|
|
588 |
# inputs=[chat_input, chatbot],
|
589 |
# outputs=[chatbot]
|
590 |
#).then(lambda: "", None, chat_input)
|
591 |
+
"""
|
592 |
send_button.click(
|
593 |
lambda msg: (gr.update(value=""), msg), # clears textbox immediately
|
594 |
inputs=[chat_input],
|
|
|
608 |
inputs=[chat_input, chatbot],
|
609 |
outputs=[chatbot]
|
610 |
)
|
611 |
+
"""
|
612 |
+
send_button.click(
|
613 |
+
fn=lambda msg: (msg, gr.update(value="")),
|
614 |
+
inputs=[chat_input],
|
615 |
+
outputs=[gr.State(), chat_input] # Store original msg in State
|
616 |
+
).then(
|
617 |
+
fn=start_generation,
|
618 |
+
inputs=[gr.State(), chatbot], # Use the stored message
|
619 |
+
outputs=[gr.State(), chatbot] # Store again for streaming
|
620 |
+
).then(
|
621 |
+
fn=continue_generation,
|
622 |
+
inputs=[gr.State(), chatbot], # Stream using same message
|
623 |
+
outputs=[chatbot]
|
624 |
+
)
|
625 |
+
|
626 |
+
chat_input.submit(
|
627 |
+
fn=lambda msg: (msg, gr.update(value="")),
|
628 |
+
inputs=[chat_input],
|
629 |
+
outputs=[gr.State(), chat_input]
|
630 |
+
).then(
|
631 |
+
fn=start_generation,
|
632 |
+
inputs=[gr.State(), chatbot],
|
633 |
+
outputs=[gr.State(), chatbot]
|
634 |
+
).then(
|
635 |
+
fn=continue_generation,
|
636 |
+
inputs=[gr.State(), chatbot],
|
637 |
+
outputs=[chatbot]
|
638 |
+
)
|
639 |
# JavaScript for UI enhancements
|
640 |
gr.HTML("""
|
641 |
<script>
|