Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -255,17 +255,17 @@ if __name__ == "__main__":
|
|
255 |
gr.Markdown("# Website Chat Assistant")
|
256 |
gr.Markdown("Ask questions about the website.")
|
257 |
|
258 |
-
chatbot = gr.Chatbot(height=600)
|
259 |
msg = gr.Textbox(placeholder="Ask a question...", label="Your question")
|
260 |
clear = gr.Button("Clear")
|
261 |
|
262 |
def user(user_message, history):
|
263 |
-
return "", history + [
|
264 |
|
265 |
def bot(history):
|
266 |
-
if history and history[-1][
|
267 |
-
for response in chat_response(history[-1][
|
268 |
-
history
|
269 |
yield history
|
270 |
|
271 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
@@ -274,10 +274,10 @@ if __name__ == "__main__":
|
|
274 |
|
275 |
clear.click(lambda: None, None, chatbot, queue=False)
|
276 |
|
277 |
-
# Launch with
|
278 |
demo.queue()
|
279 |
demo.launch(
|
280 |
-
server_name="
|
281 |
server_port=7860,
|
282 |
share=False
|
283 |
)
|
|
|
255 |
gr.Markdown("# Website Chat Assistant")
|
256 |
gr.Markdown("Ask questions about the website.")
|
257 |
|
258 |
+
chatbot = gr.Chatbot(height=600, type='messages')
|
259 |
msg = gr.Textbox(placeholder="Ask a question...", label="Your question")
|
260 |
clear = gr.Button("Clear")
|
261 |
|
262 |
def user(user_message, history):
|
263 |
+
return "", history + [{"role": "user", "content": user_message}]
|
264 |
|
265 |
def bot(history):
|
266 |
+
if history and history[-1]["role"] == "user":
|
267 |
+
for response in chat_response(history[-1]["content"], history[:-1]):
|
268 |
+
history.append({"role": "assistant", "content": response})
|
269 |
yield history
|
270 |
|
271 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
|
|
274 |
|
275 |
clear.click(lambda: None, None, chatbot, queue=False)
|
276 |
|
277 |
+
# Launch with configuration for Hugging Face Spaces
|
278 |
demo.queue()
|
279 |
demo.launch(
|
280 |
+
server_name="0.0.0.0",
|
281 |
server_port=7860,
|
282 |
share=False
|
283 |
)
|