Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,20 +32,21 @@ def respond(message, history):
|
|
| 32 |
print("Query received:", message)
|
| 33 |
print("Chat history:", history)
|
| 34 |
|
|
|
|
| 35 |
if not history:
|
| 36 |
history = []
|
| 37 |
|
| 38 |
try:
|
| 39 |
-
# Determine if the query should access Google Sheets
|
| 40 |
if "district" in message.lower() or "developer" in message.lower():
|
| 41 |
response = get_apartment_data(message)
|
| 42 |
else:
|
| 43 |
messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
| 44 |
-
for
|
| 45 |
-
if
|
| 46 |
-
messages.append({"role": "user", "content":
|
| 47 |
-
|
| 48 |
-
messages.append({"role": "assistant", "content":
|
|
|
|
| 49 |
messages.append({"role": "user", "content": message})
|
| 50 |
|
| 51 |
# Generate response from model
|
|
@@ -58,16 +59,18 @@ def respond(message, history):
|
|
| 58 |
response = generated_response["choices"][0]["message"]["content"]
|
| 59 |
|
| 60 |
# Append the new interaction to the history
|
| 61 |
-
history.append(
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Error processing query: {e}")
|
| 66 |
-
return "An error occurred while processing your query."
|
| 67 |
|
| 68 |
# Set up Gradio Chat Interface
|
| 69 |
chat_interface = gr.ChatInterface(
|
| 70 |
fn=respond,
|
|
|
|
| 71 |
examples=[
|
| 72 |
"What apartments are available in Bostandyk?",
|
| 73 |
"Tell me about BI Group.",
|
|
|
|
| 32 |
print("Query received:", message)
|
| 33 |
print("Chat history:", history)
|
| 34 |
|
| 35 |
+
# Initialize history as a list of dictionaries if empty
|
| 36 |
if not history:
|
| 37 |
history = []
|
| 38 |
|
| 39 |
try:
|
|
|
|
| 40 |
if "district" in message.lower() or "developer" in message.lower():
|
| 41 |
response = get_apartment_data(message)
|
| 42 |
else:
|
| 43 |
messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
| 44 |
+
for entry in history:
|
| 45 |
+
if entry["role"] == "user":
|
| 46 |
+
messages.append({"role": "user", "content": entry["content"]})
|
| 47 |
+
elif entry["role"] == "assistant":
|
| 48 |
+
messages.append({"role": "assistant", "content": entry["content"]})
|
| 49 |
+
|
| 50 |
messages.append({"role": "user", "content": message})
|
| 51 |
|
| 52 |
# Generate response from model
|
|
|
|
| 59 |
response = generated_response["choices"][0]["message"]["content"]
|
| 60 |
|
| 61 |
# Append the new interaction to the history
|
| 62 |
+
history.append({"role": "user", "content": message})
|
| 63 |
+
history.append({"role": "assistant", "content": response})
|
| 64 |
+
return history
|
| 65 |
|
| 66 |
except Exception as e:
|
| 67 |
print(f"Error processing query: {e}")
|
| 68 |
+
return [{"role": "assistant", "content": "An error occurred while processing your query."}]
|
| 69 |
|
| 70 |
# Set up Gradio Chat Interface
|
| 71 |
chat_interface = gr.ChatInterface(
|
| 72 |
fn=respond,
|
| 73 |
+
chatbot="Your Assistant",
|
| 74 |
examples=[
|
| 75 |
"What apartments are available in Bostandyk?",
|
| 76 |
"Tell me about BI Group.",
|