RomZay commited on
Commit
38c0cd8
·
verified ·
1 Parent(s): 5e06b4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -102,7 +102,10 @@ def respond(message, api_key, max_tokens, top_p, temperature):
102
  return history, "Error: " + response.json().get("error", "Unknown error occurred.")
103
 
104
  def render_message(history):
105
- messages_html = ""
 
 
 
106
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
107
  if user_message:
108
  messages_html += f"<div style='display: flex; align-items: center; margin-bottom: 10px;'>"
@@ -115,9 +118,19 @@ def render_message(history):
115
  if assistant_pic:
116
  messages_html += f"<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>"
117
  messages_html += f"{assistant_message}</div><br>"
118
-
 
 
 
 
 
 
 
 
 
119
  return messages_html
120
 
 
121
  with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #ccc; padding: 10px; background-color: #f9f9f9;}") as demo:
122
 
123
  with gr.Column(visible=True) as auth_view:
 
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" style="height: 400px; overflow-y: auto; border: 1px solid #ccc; padding: 10px; background-color: #f9f9f9;">
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;'>"
 
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
+ messages_html += """
123
+ </div>
124
+ </div>
125
+ <script>
126
+ var chatbox = document.getElementById('chatbox-container');
127
+ chatbox.scrollTop = chatbox.scrollHeight;
128
+ </script>
129
+ """
130
+
131
  return messages_html
132
 
133
+
134
  with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #ccc; padding: 10px; background-color: #f9f9f9;}") as demo:
135
 
136
  with gr.Column(visible=True) as auth_view: