Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -101,31 +101,27 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
101 |
else:
|
102 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
103 |
|
104 |
-
def
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
|
119 |
-
return previous_html + new_message_html
|
120 |
|
|
|
121 |
|
122 |
-
def render_message(history):
|
123 |
-
chat_html = ""
|
124 |
-
|
125 |
-
for message in history:
|
126 |
-
chat_html = append_message(message, chat_html)
|
127 |
-
|
128 |
-
return chat_html
|
129 |
|
130 |
with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}") as demo:
|
131 |
|
@@ -140,7 +136,7 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
140 |
with gr.Column(visible=False) as chat_view:
|
141 |
gr.Markdown("## P-MSQ Chat Interface")
|
142 |
|
143 |
-
chatbot_output = gr.HTML()
|
144 |
|
145 |
msg_input = gr.Textbox(
|
146 |
show_label=False,
|
@@ -167,9 +163,7 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
167 |
|
168 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
169 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
170 |
-
|
171 |
-
updated_html = render_message(history)
|
172 |
-
return updated_html, history, "", message
|
173 |
|
174 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
175 |
return "", []
|
@@ -185,8 +179,8 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
185 |
return render_message(history), history
|
186 |
|
187 |
msg_input.submit(user_interaction,
|
188 |
-
|
189 |
-
|
190 |
|
191 |
send_btn.click(user_interaction,
|
192 |
inputs=[msg_input, history_state, api_key_input, max_tokens, top_p, temperature],
|
|
|
101 |
else:
|
102 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
103 |
|
104 |
+
def render_message(history):
|
105 |
+
messages_html = """
|
106 |
+
<div id="chatbox-container" class="chatbox">
|
107 |
+
<div id="messages">"""
|
108 |
+
|
109 |
+
for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
|
110 |
+
if user_message:
|
111 |
+
messages_html += f"<div style='display: flex; align-items: center; margin-bottom: 10px;'>"
|
112 |
+
if user_pic:
|
113 |
+
messages_html += f"<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>"
|
114 |
+
messages_html += f"{user_message}</div><br>"
|
115 |
|
116 |
+
if assistant_message:
|
117 |
+
messages_html += f"<div style='display: flex; align-items: center; margin-bottom: 10px;'>"
|
118 |
+
if assistant_pic:
|
119 |
+
messages_html += f"<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>"
|
120 |
+
messages_html += f"{assistant_message}</div><br>"
|
121 |
|
|
|
122 |
|
123 |
+
return messages_html
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}") as demo:
|
127 |
|
|
|
136 |
with gr.Column(visible=False) as chat_view:
|
137 |
gr.Markdown("## P-MSQ Chat Interface")
|
138 |
|
139 |
+
chatbot_output = gr.HTML(elem_id="chatbox")
|
140 |
|
141 |
msg_input = gr.Textbox(
|
142 |
show_label=False,
|
|
|
163 |
|
164 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
165 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
166 |
+
return render_message(history), history, "", message
|
|
|
|
|
167 |
|
168 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
169 |
return "", []
|
|
|
179 |
return render_message(history), history
|
180 |
|
181 |
msg_input.submit(user_interaction,
|
182 |
+
inputs=[msg_input, history_state, api_key_input, max_tokens, top_p, temperature],
|
183 |
+
outputs=[chatbot_output, history_state, msg_input, last_message_state])
|
184 |
|
185 |
send_btn.click(user_interaction,
|
186 |
inputs=[msg_input, history_state, api_key_input, max_tokens, top_p, temperature],
|