Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +103 -23
src/streamlit_app.py
CHANGED
|
@@ -2,6 +2,59 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
import uuid
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Constants
|
| 6 |
WEBHOOK_URL = "https://shahrukh1472.app.n8n.cloud/webhook/2f9e9f00-7ce8-485e-bd34-0df1014c4303"
|
| 7 |
BEARER_TOKEN = "TestCreds99"
|
|
@@ -25,35 +78,62 @@ def send_message_to_llm(session_id, message):
|
|
| 25 |
return f"Error: {response.status_code} - {response.text}"
|
| 26 |
|
| 27 |
def main():
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
with st.chat_message(message["role"]):
|
| 39 |
-
st.write(message["content"])
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
if user_input:
|
| 45 |
-
# Add user message to chat history
|
| 46 |
-
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 47 |
-
with st.chat_message("user"):
|
| 48 |
-
st.write(user_input)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
if __name__ == "__main__":
|
| 59 |
main()
|
|
|
|
| 2 |
import requests
|
| 3 |
import uuid
|
| 4 |
|
| 5 |
+
# styling
|
| 6 |
+
st.set_page_config(page_title="Real Estate AI π¬", page_icon="π€", layout="centered")
|
| 7 |
+
|
| 8 |
+
# Custom CSS for beautification
|
| 9 |
+
st.markdown("""
|
| 10 |
+
<style>
|
| 11 |
+
body {
|
| 12 |
+
background-color: #3486eb;
|
| 13 |
+
}
|
| 14 |
+
.stApp {
|
| 15 |
+
background: linear-gradient(135deg, #43104a, #131469);
|
| 16 |
+
;
|
| 17 |
+
}
|
| 18 |
+
.main {
|
| 19 |
+
padding: 2rem;
|
| 20 |
+
border-radius: 15px;
|
| 21 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
| 22 |
+
background-color: white;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
div[data-testid="stChatMessageAvatarAssistant"] {
|
| 26 |
+
color: #a192fc;
|
| 27 |
+
background: rgb(38, 39, 48);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
div[data-testid="stChatMessageAvatarUser"] {
|
| 31 |
+
color: #e492fc;
|
| 32 |
+
background: rgb(38, 39, 48);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
[data-testid="stChatMessage"][aria-label*="user"],
|
| 36 |
+
[data-testid="stChatMessage"]:has([data-testid="stChatMessageAvatarUser"]) {
|
| 37 |
+
background-color: rgb(38, 39, 48);
|
| 38 |
+
color: black;
|
| 39 |
+
margin-left: auto;
|
| 40 |
+
text-align: right;
|
| 41 |
+
border-radius: 18px 18px 0 18px;
|
| 42 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
[data-testid="stChatMessage"][aria-label*="assistant"],
|
| 46 |
+
[data-testid="stChatMessage"]:has([data-testid="stChatMessageAvatarAssistant"]) {
|
| 47 |
+
background-color: rgb(38, 39, 48);
|
| 48 |
+
color: black;
|
| 49 |
+
margin-right: auto;
|
| 50 |
+
text-align: left;
|
| 51 |
+
border-radius: 18px 18px 18px 0;
|
| 52 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
</style>
|
| 56 |
+
""", unsafe_allow_html=True)
|
| 57 |
+
|
| 58 |
# Constants
|
| 59 |
WEBHOOK_URL = "https://shahrukh1472.app.n8n.cloud/webhook/2f9e9f00-7ce8-485e-bd34-0df1014c4303"
|
| 60 |
BEARER_TOKEN = "TestCreds99"
|
|
|
|
| 78 |
return f"Error: {response.status_code} - {response.text}"
|
| 79 |
|
| 80 |
def main():
|
| 81 |
+
|
| 82 |
+
st.sidebar.title("π Navigation")
|
| 83 |
+
page = st.sidebar.radio("", ["Chatbot", "Information"])
|
| 84 |
+
|
| 85 |
+
if page == "Chatbot":
|
| 86 |
+
|
| 87 |
+
st.title("Hey, I'm your Real-estate AI Agent. Let's Chat!")
|
| 88 |
+
st.caption("Your smart assistant for finding the perfect property β faster, easier, smarter.")
|
| 89 |
+
|
| 90 |
+
# Initialize session state
|
| 91 |
+
if "messages" not in st.session_state:
|
| 92 |
+
st.session_state.messages = []
|
| 93 |
+
if "session_id" not in st.session_state:
|
| 94 |
+
st.session_state.session_id = generate_session_id()
|
| 95 |
+
|
| 96 |
+
# Display chat messages
|
| 97 |
+
for message in st.session_state.messages:
|
| 98 |
+
with st.chat_message(message["role"]):
|
| 99 |
+
st.write(message["content"])
|
| 100 |
+
|
| 101 |
+
# User input
|
| 102 |
+
user_input = st.chat_input("Type your message here...")
|
| 103 |
|
| 104 |
+
if user_input:
|
| 105 |
+
# Add user message to chat history
|
| 106 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 107 |
+
with st.chat_message("user"):
|
| 108 |
+
st.write(user_input)
|
| 109 |
|
| 110 |
+
# Get LLM response
|
| 111 |
+
llm_response = send_message_to_llm(st.session_state.session_id, user_input)
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
# Add LLM response to chat history
|
| 114 |
+
st.session_state.messages.append({"role": "assistant", "content": llm_response})
|
| 115 |
+
with st.chat_message("assistant"):
|
| 116 |
+
st.write(llm_response)
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
elif page == "Information":
|
| 120 |
+
st.title("About the Real Estate Chatbot")
|
| 121 |
+
st.markdown("""
|
| 122 |
+
### π€ **What This Chatbot Does**
|
| 123 |
+
This AI chatbot helps you:
|
| 124 |
+
- ποΈ Find properties that match your preferences
|
| 125 |
+
- π° Compare price trends in different locations
|
| 126 |
+
- π Analyze market growth and investment potential
|
| 127 |
+
- π Get instant answers to real estate queries
|
| 128 |
|
| 129 |
+
### π **Future Additions**
|
| 130 |
+
- Integration with live property listings
|
| 131 |
+
- Predictive price estimation
|
| 132 |
+
- Neighborhood insights and amenities
|
| 133 |
|
| 134 |
+
---
|
| 135 |
+
π¬ *Switch to the Chatbot page from the sidebar to start talking!*
|
| 136 |
+
""")
|
| 137 |
+
|
| 138 |
if __name__ == "__main__":
|
| 139 |
main()
|