Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
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"""
|