LucidMinds3ye commited on
Commit
be0447d
Β·
verified Β·
1 Parent(s): 1e1854c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -61,7 +61,7 @@ def handle_product_inquiry(product_type, model=None):
61
  response += f"\n- {model_name}: {details['name']} ({details['price']})"
62
  return response
63
 
64
- # Main chat function
65
  def chat_with_bot(message, chat_history):
66
  user_message = message.lower()
67
  bot_response = ""
@@ -130,15 +130,12 @@ def chat_with_bot(message, chat_history):
130
  # Add a small delay to make it feel more natural
131
  time.sleep(0.5)
132
 
133
- # Append to chat history
134
- chat_history.append((message, bot_response))
 
135
 
136
  return "", chat_history
137
 
138
- # Function to handle example clicks
139
- def example_click(example):
140
- return example
141
-
142
  # Custom CSS for styling
143
  custom_css = """
144
  #chatbot {
@@ -195,7 +192,13 @@ with gr.Blocks(css=custom_css, title="TechGadget Store Support") as demo:
195
 
196
  with gr.Row():
197
  with gr.Column(scale=2):
198
- chatbot = gr.Chatbot(label="Conversation", elem_id="chatbot")
 
 
 
 
 
 
199
  with gr.Row():
200
  msg = gr.Textbox(
201
  label="Type your message here...",
@@ -209,22 +212,20 @@ with gr.Blocks(css=custom_css, title="TechGadget Store Support") as demo:
209
  with gr.Column(scale=1):
210
  gr.Markdown("### πŸ’‘ Common Questions")
211
 
212
- # Create example buttons that properly update the message box
213
- with gr.Row():
214
- gr.Examples(
215
- examples=[
216
- ["What are your store hours?"],
217
- ["Where are you located?"],
218
- ["What smartphones do you sell?"],
219
- ["What is your return policy?"],
220
- ["Do you offer free shipping?"],
221
- ["What can you help with?"],
222
- ["Tell me about your laptops"]
223
- ],
224
- inputs=msg,
225
- label="Click any question to try it!",
226
- elem_classes="example-btn"
227
- )
228
 
229
  gr.Markdown("### πŸͺ Store Information")
230
  gr.Markdown(f"""
 
61
  response += f"\n- {model_name}: {details['name']} ({details['price']})"
62
  return response
63
 
64
+ # Main chat function - updated for gr.Messages format
65
  def chat_with_bot(message, chat_history):
66
  user_message = message.lower()
67
  bot_response = ""
 
130
  # Add a small delay to make it feel more natural
131
  time.sleep(0.5)
132
 
133
+ # Append to chat history using the new Messages format
134
+ chat_history.append({"role": "user", "content": message})
135
+ chat_history.append({"role": "assistant", "content": bot_response})
136
 
137
  return "", chat_history
138
 
 
 
 
 
139
  # Custom CSS for styling
140
  custom_css = """
141
  #chatbot {
 
192
 
193
  with gr.Row():
194
  with gr.Column(scale=2):
195
+ # Updated to use the new Messages format
196
+ chatbot = gr.Chatbot(
197
+ label="Conversation",
198
+ elem_id="chatbot",
199
+ type="messages",
200
+ show_copy_button=True
201
+ )
202
  with gr.Row():
203
  msg = gr.Textbox(
204
  label="Type your message here...",
 
212
  with gr.Column(scale=1):
213
  gr.Markdown("### πŸ’‘ Common Questions")
214
 
215
+ # Create example buttons with correct parameters
216
+ examples = gr.Examples(
217
+ examples=[
218
+ ["What are your store hours?"],
219
+ ["Where are you located?"],
220
+ ["What smartphones do you sell?"],
221
+ ["What is your return policy?"],
222
+ ["Do you offer free shipping?"],
223
+ ["What can you help with?"],
224
+ ["Tell me about your laptops"]
225
+ ],
226
+ inputs=msg,
227
+ label="Click any question to try it!"
228
+ )
 
 
229
 
230
  gr.Markdown("### πŸͺ Store Information")
231
  gr.Markdown(f"""