Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,28 +84,7 @@ 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 |
-
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;">
|
| 90 |
-
<div id="messages">"""
|
| 91 |
|
| 92 |
-
for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
|
| 93 |
-
if user_message:
|
| 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;'>{gr.Markdown(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;'>{gr.Markdown(assistant_message)}</span>
|
| 105 |
-
</div><br>"""
|
| 106 |
-
|
| 107 |
-
messages_html += "</div></div>"
|
| 108 |
-
return messages_html
|
| 109 |
|
| 110 |
js = """
|
| 111 |
function Scrolldown() {
|
|
@@ -168,12 +147,21 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow: auto; border: 1px solid #
|
|
| 168 |
history_state = gr.State([])
|
| 169 |
last_message_state = gr.State("")
|
| 170 |
|
| 171 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
| 179 |
return "", []
|
|
|
|
| 84 |
else:
|
| 85 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
js = """
|
| 90 |
function Scrolldown() {
|
|
|
|
| 147 |
history_state = gr.State([])
|
| 148 |
last_message_state = gr.State("")
|
| 149 |
|
| 150 |
+
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
|
|
|
|
|
|
|
|
|
| 151 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
| 152 |
+
|
| 153 |
+
for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
|
| 154 |
+
with chatbot_output:
|
| 155 |
+
if user_message:
|
| 156 |
+
with gr.Row():
|
| 157 |
+
gr.Image(value=user_pic, label=user_profile, width=40, height=40)
|
| 158 |
+
gr.Markdown(f"**{user_profile}:** {user_message}")
|
| 159 |
+
if assistant_message:
|
| 160 |
+
with gr.Row():
|
| 161 |
+
gr.Image(value=assistant_pic, label=assistant_profile, width=40, height=40)
|
| 162 |
+
gr.Markdown(f"**{assistant_profile}:** {assistant_message}")
|
| 163 |
+
|
| 164 |
+
return history, ""
|
| 165 |
|
| 166 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
| 167 |
return "", []
|