Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,26 +71,48 @@ def render_message(history):
|
|
| 71 |
return messages_html
|
| 72 |
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
system_message = gr.Textbox(value="You are P-MSQ (Messaging Service Query), a friendly AI Chatbot that can help in any situations.", label="System message")
|
|
|
|
|
|
|
| 78 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=1024, step=1, label="Max new tokens")
|
| 79 |
top_p = gr.Slider(minimum=0, maximum=2, value=0.8, step=0.1, label="Top P")
|
| 80 |
temperature = gr.Slider(minimum=0.1, maximum=1, value=0.7, step=0.1, label="Temperature")
|
| 81 |
|
| 82 |
history_state = gr.State([])
|
|
|
|
|
|
|
| 83 |
def user_interaction(message, history, system_message, max_tokens, top_p, temperature):
|
| 84 |
history, assistant_reply = respond(message, history, system_message, max_tokens, top_p, temperature)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
return render_message(history), history
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
demo.launch()
|
|
|
|
| 71 |
return messages_html
|
| 72 |
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
+
gr.Markdown("## P-MSQ Chat Interface with Profile Pictures")
|
| 75 |
+
gr.Markdown("""
|
| 76 |
+
Welcome to the **P-MSQ** (Messaging Service Query) chat interface!
|
| 77 |
+
You are interacting with a friendly AI chatbot that can assist you in various situations.
|
| 78 |
+
Use the text input box below to start chatting.
|
| 79 |
+
""")
|
| 80 |
+
|
| 81 |
+
with gr.Box():
|
| 82 |
+
chatbot_output = gr.HTML()
|
| 83 |
+
|
| 84 |
+
with gr.Row():
|
| 85 |
+
msg_input = gr.Textbox(show_label=False, placeholder="Type your message here...", lines=2)
|
| 86 |
+
send_btn = gr.Button("Send")
|
| 87 |
+
regen_btn = gr.Button("Regenerate")
|
| 88 |
|
| 89 |
system_message = gr.Textbox(value="You are P-MSQ (Messaging Service Query), a friendly AI Chatbot that can help in any situations.", label="System message")
|
| 90 |
+
|
| 91 |
+
gr.Markdown("### Settings")
|
| 92 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=1024, step=1, label="Max new tokens")
|
| 93 |
top_p = gr.Slider(minimum=0, maximum=2, value=0.8, step=0.1, label="Top P")
|
| 94 |
temperature = gr.Slider(minimum=0.1, maximum=1, value=0.7, step=0.1, label="Temperature")
|
| 95 |
|
| 96 |
history_state = gr.State([])
|
| 97 |
+
last_message_state = gr.State("")
|
| 98 |
+
|
| 99 |
def user_interaction(message, history, system_message, max_tokens, top_p, temperature):
|
| 100 |
history, assistant_reply = respond(message, history, system_message, max_tokens, top_p, temperature)
|
| 101 |
+
return render_message(history), history, "", message
|
| 102 |
+
|
| 103 |
+
def regenerate_response(history, last_message, system_message, max_tokens, top_p, temperature):
|
| 104 |
+
if last_message:
|
| 105 |
+
history, assistant_reply = respond(last_message, history, system_message, max_tokens, top_p, temperature)
|
| 106 |
+
return render_message(history), history
|
| 107 |
return render_message(history), history
|
| 108 |
|
| 109 |
+
send_btn.click(user_interaction,
|
| 110 |
+
inputs=[msg_input, history_state, system_message, max_tokens, top_p, temperature],
|
| 111 |
+
outputs=[chatbot_output, history_state, msg_input, last_message_state])
|
| 112 |
|
| 113 |
+
regen_btn.click(regenerate_response,
|
| 114 |
+
inputs=[history_state, last_message_state, system_message, max_tokens, top_p, temperature],
|
| 115 |
+
outputs=[chatbot_output, history_state])
|
| 116 |
|
| 117 |
if __name__ == "__main__":
|
| 118 |
demo.launch()
|