Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -103,6 +103,7 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
| 103 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
| 104 |
|
| 105 |
|
|
|
|
| 106 |
def render_message(history):
|
| 107 |
messages_html = """
|
| 108 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;">
|
|
@@ -121,7 +122,7 @@ def render_message(history):
|
|
| 121 |
messages_html += f"<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>"
|
| 122 |
messages_html += f"<span style='color: white;'>{assistant_message}</span></div><br>"
|
| 123 |
|
| 124 |
-
messages_html += "</div></div>"
|
| 125 |
return messages_html
|
| 126 |
|
| 127 |
|
|
@@ -165,17 +166,21 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
| 165 |
last_message_state = gr.State("")
|
| 166 |
|
| 167 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
|
|
|
| 168 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
|
|
|
| 169 |
full_history_html = render_message(history)
|
|
|
|
| 170 |
scroll_script = """
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
|
|
|
| 103 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
| 104 |
|
| 105 |
|
| 106 |
+
|
| 107 |
def render_message(history):
|
| 108 |
messages_html = """
|
| 109 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;">
|
|
|
|
| 122 |
messages_html += f"<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>"
|
| 123 |
messages_html += f"<span style='color: white;'>{assistant_message}</span></div><br>"
|
| 124 |
|
| 125 |
+
messages_html += "</div></div>" # Close the messages and chatbox container
|
| 126 |
return messages_html
|
| 127 |
|
| 128 |
|
|
|
|
| 166 |
last_message_state = gr.State("")
|
| 167 |
|
| 168 |
def user_interaction(message, history, api_key, max_tokens, top_p, temperature):
|
| 169 |
+
|
| 170 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
| 171 |
+
|
| 172 |
full_history_html = render_message(history)
|
| 173 |
+
|
| 174 |
scroll_script = """
|
| 175 |
+
<script>
|
| 176 |
+
window.onload = function() {
|
| 177 |
+
const container = document.getElementById('chatbox-container');
|
| 178 |
+
container.scrollTop = container.scrollHeight; // Scroll to the bottom
|
| 179 |
+
};
|
| 180 |
+
</script>"""
|
| 181 |
+
|
| 182 |
+
return full_history_html + scroll_script, history, "", message
|
| 183 |
+
|
| 184 |
|
| 185 |
|
| 186 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|