Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,7 +84,6 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
| 84 |
else:
|
| 85 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
| 86 |
|
| 87 |
-
|
| 88 |
def render_message(history):
|
| 89 |
messages_html = """
|
| 90 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;">
|
|
@@ -95,22 +94,19 @@ def render_message(history):
|
|
| 95 |
messages_html += f"""
|
| 96 |
<div style='display: flex; align-items: center; margin-bottom: 10px;'>
|
| 97 |
<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
|
| 98 |
-
<span style='color: white;'>
|
| 99 |
-
<span style='color: white;'>{gr.Markdown(user_message)}</span>
|
| 100 |
</div><br>"""
|
| 101 |
|
| 102 |
if assistant_message:
|
| 103 |
messages_html += f"""
|
| 104 |
<div style='display: flex; align-items: center; margin-bottom: 10px;'>
|
| 105 |
<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
|
| 106 |
-
<span style='color: white;'>
|
| 107 |
-
<span style='color: white;'>{gr.Markdown(assistant_message)}</span>
|
| 108 |
</div><br>"""
|
| 109 |
|
| 110 |
messages_html += "</div></div>"
|
| 111 |
return messages_html
|
| 112 |
|
| 113 |
-
|
| 114 |
js = """
|
| 115 |
function Scrolldown() {
|
| 116 |
const messagesContainer = document.getElementById('chatbox-container');
|
|
@@ -173,20 +169,11 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow: auto; border: 1px solid #
|
|
| 173 |
last_message_state = gr.State("")
|
| 174 |
|
| 175 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
|
|
|
|
|
|
|
|
|
| 176 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
| 177 |
-
|
| 178 |
-
for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
|
| 179 |
-
with chatbot_output:
|
| 180 |
-
if user_message:
|
| 181 |
-
with gr.Row():
|
| 182 |
-
gr.Image(value=user_pic, label=user_profile, width=40, height=40)
|
| 183 |
-
gr.Markdown(f"**{user_profile}:** {user_message}")
|
| 184 |
-
if assistant_message:
|
| 185 |
-
with gr.Row():
|
| 186 |
-
gr.Image(value=assistant_pic, label=assistant_profile, width=40, height=40)
|
| 187 |
-
gr.Markdown(f"**{assistant_profile}:** {assistant_message}")
|
| 188 |
-
|
| 189 |
-
return history, ""
|
| 190 |
|
| 191 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
| 192 |
return "", []
|
|
|
|
| 84 |
else:
|
| 85 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
| 86 |
|
|
|
|
| 87 |
def render_message(history):
|
| 88 |
messages_html = """
|
| 89 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;">
|
|
|
|
| 94 |
messages_html += f"""
|
| 95 |
<div style='display: flex; align-items: center; margin-bottom: 10px;'>
|
| 96 |
<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
|
| 97 |
+
<span style='color: white;'>**{user_profile}**: {user_message}</span>
|
|
|
|
| 98 |
</div><br>"""
|
| 99 |
|
| 100 |
if assistant_message:
|
| 101 |
messages_html += f"""
|
| 102 |
<div style='display: flex; align-items: center; margin-bottom: 10px;'>
|
| 103 |
<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
|
| 104 |
+
<span style='color: white;'>**{assistant_profile}**: {assistant_message}</span>
|
|
|
|
| 105 |
</div><br>"""
|
| 106 |
|
| 107 |
messages_html += "</div></div>"
|
| 108 |
return messages_html
|
| 109 |
|
|
|
|
| 110 |
js = """
|
| 111 |
function Scrolldown() {
|
| 112 |
const messagesContainer = document.getElementById('chatbox-container');
|
|
|
|
| 169 |
last_message_state = gr.State("")
|
| 170 |
|
| 171 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
| 172 |
+
loading_message = history + [(message, "Loading...", "You", "P-ALPLE", USER_PIC_PATH, ASSISTANT_PIC_PATH)]
|
| 173 |
+
yield render_message(loading_message), loading_message, ""
|
| 174 |
+
|
| 175 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
| 176 |
+
yield render_message(history), history, ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
| 179 |
return "", []
|