Solarum Asteridion commited on
Commit
cb396b0
·
verified ·
1 Parent(s): cc1f6d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -30
app.py CHANGED
@@ -72,30 +72,6 @@ def generate_response(user_message, conversation_history):
72
  logger.error(f"Error generating response: {e}")
73
  return "Sorry, I encountered an error while processing your request."
74
 
75
- def format_message(message, is_user=True):
76
- avatar = "🧑" if is_user else "🤖"
77
- timestamp = datetime.datetime.now().strftime("%H:%M")
78
- if is_user:
79
- return f"""
80
- <div style="text-align: right; margin-bottom: 10px;">
81
- <span style="background-color: #dcf8c6; color: #000; padding: 10px; border-radius: 10px; display: inline-block; max-width: 80%;">
82
- {message}
83
- <div style="font-size: 0.8em; color: #999;">{timestamp}</div>
84
- </span>
85
- <span style="font-size: 1.5em; margin-left: 5px;">{avatar}</span>
86
- </div>
87
- """
88
- else:
89
- return f"""
90
- <div style="text-align: left; margin-bottom: 10px;">
91
- <span style="font-size: 1.5em; margin-right: 5px;">{avatar}</span>
92
- <span style="background-color: #f1f0f0; color: #000; padding: 10px; border-radius: 10px; display: inline-block; max-width: 80%;">
93
- {message}
94
- <div style="font-size: 0.8em; color: #999;">{timestamp}</div>
95
- </span>
96
- </div>
97
- """
98
-
99
  def chatbot_interface(user_message, history):
100
  if history is None:
101
  history = []
@@ -192,16 +168,12 @@ with gr.Blocks(css="""
192
  send = gr.Button("➤", elem_id="send-button")
193
  with gr.Row():
194
  clear = gr.Button("Clear Chat", elem_id="clear-button")
195
-
196
  def update_chat(user_message, history):
197
  if user_message.strip() == "":
198
  return history, history # Do not process empty messages
199
  history, updated_history = chatbot_interface(user_message, history)
200
- formatted_history = [
201
- format_message(msg['content'], is_user=(msg['role'] == 'user'))
202
- for msg in updated_history
203
- ]
204
- return formatted_history, updated_history
205
 
206
  send.click(
207
  update_chat,
 
72
  logger.error(f"Error generating response: {e}")
73
  return "Sorry, I encountered an error while processing your request."
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  def chatbot_interface(user_message, history):
76
  if history is None:
77
  history = []
 
168
  send = gr.Button("➤", elem_id="send-button")
169
  with gr.Row():
170
  clear = gr.Button("Clear Chat", elem_id="clear-button")
171
+
172
  def update_chat(user_message, history):
173
  if user_message.strip() == "":
174
  return history, history # Do not process empty messages
175
  history, updated_history = chatbot_interface(user_message, history)
176
+ return history, updated_history
 
 
 
 
177
 
178
  send.click(
179
  update_chat,