Spaces:
Build error
Build error
1232
Browse files
app.py
CHANGED
|
@@ -254,32 +254,36 @@ def chat_with_session(message, history, session_id=None):
|
|
| 254 |
if session_id is None:
|
| 255 |
session_id = str(uuid.uuid4())
|
| 256 |
answer = get_context_and_answer(message, history, session_id)
|
| 257 |
-
return answer, session_id # Return answer and session_id for state tracking
|
| 258 |
|
| 259 |
-
if
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
chat_interface = gr.ChatInterface(
|
| 265 |
-
fn=chat_with_session,
|
| 266 |
-
additional_inputs=[session_id_state],
|
| 267 |
-
title="ASKXENO",
|
| 268 |
-
description="Ask anything about XENO's financial services.",
|
| 269 |
-
theme="soft",
|
| 270 |
-
examples=[
|
| 271 |
-
["How do I open a XENO account?", None],
|
| 272 |
-
["What are the fees?", None],
|
| 273 |
-
["Tell me about investment options", None]
|
| 274 |
-
]
|
| 275 |
-
)
|
| 276 |
|
| 277 |
-
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
if session_id is None:
|
| 255 |
session_id = str(uuid.uuid4())
|
| 256 |
answer = get_context_and_answer(message, history, session_id)
|
|
|
|
| 257 |
|
| 258 |
+
if history is None:
|
| 259 |
+
history = []
|
| 260 |
+
# Append user message and assistant answer to chat history as dicts:
|
| 261 |
+
history.append({"role": "user", "content": message})
|
| 262 |
+
history.append({"role": "assistant", "content": answer})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
+
return history, session_id
|
| 265 |
|
| 266 |
+
if __name__ == "__main__":
|
| 267 |
+
session_id_state = gr.State(value=str(uuid.uuid4()))
|
| 268 |
+
|
| 269 |
+
iface = gr.ChatInterface(
|
| 270 |
+
fn=chat_with_session,
|
| 271 |
+
additional_inputs=[session_id_state],
|
| 272 |
+
title="ASKXENO",
|
| 273 |
+
description="Ask anything about XENO's financial services.",
|
| 274 |
+
theme="soft",
|
| 275 |
+
type="messages", # Use 'messages' format (dict with role/content)
|
| 276 |
+
examples=[
|
| 277 |
+
["How do I open a XENO account?", None],
|
| 278 |
+
["What are the fees?", None],
|
| 279 |
+
["Tell me about investment options", None]
|
| 280 |
+
]
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
# Reset session ID on clear button click:
|
| 284 |
+
iface.clear_btn.click(
|
| 285 |
+
fn=lambda: str(uuid.uuid4()),
|
| 286 |
+
outputs=[session_id_state]
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
iface.launch(share=False, server_name="0.0.0.0", server_port=7860)
|