Spaces:
Build error
Build error
Update app.py
Browse files19 unmodified lines202122232425262715 unmodified lines43444546474849505152535419 unmodified linesif history is None:history = [] # Initialize empty history if None# Convert history to the new formatformatted_history = "\n".join([f"{h['role']}: {h['content']}" for h in history[-5:]]) # Keep last 5 messages# Construct prompt with memory + document contextprompt = f"""15 unmodified lines# Extract response textanswer = response.text if hasattr(response, "text") else "Sorry, I couldn't generate a response."# Append new message to history in the correct formathistory.append({"role": "user", "content": user_input})history.append({"role": "assistant", "content": answer})return answer, history # Return both response and updated history# Create a Gradio chat interface with memory using new "messages" formatiface = gr.ChatInterface(fn=chatbot_response, title="Memory-Enabled Chatbot")19 unmodified lines2021222324252627282915 unmodified lines4546474849505152535455565719 unmodified linesif history is None:history = [] # Initialize empty history if None# Convert history to the new "messages" formatformatted_history = "\n".join([f"{msg['role'].capitalize()}: {msg['content']}" for msg in history[-5:]] # Keep last 5 messages)# Construct prompt with memory + document contextprompt = f"""15 unmodified lines# Extract response textanswer = response.text if hasattr(response, "text") else "Sorry, I couldn't generate a response."# Append messages in the correct formathistory.append({"role": "user", "content": user_input})history.append({"role": "assistant", "content": answer})return answer, history # Return both response and updated history# Create a Gradio chat interface with memory using new "messages" formatiface = gr.ChatInterface(fn=chatbot_response, title="Memory-Enabled Chatbot")
app.py+6-3