Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import uuid | |
| # styling | |
| st.set_page_config(page_title="Real Estate AI π¬", page_icon="π€", layout="centered") | |
| # Custom CSS for beautification | |
| st.markdown(""" | |
| <style> | |
| body { | |
| background-color: #3486eb; | |
| } | |
| .stApp { | |
| background: linear-gradient(135deg, #43104a, #131469); | |
| ; | |
| } | |
| .main { | |
| padding: 2rem; | |
| border-radius: 15px; | |
| box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); | |
| background-color: white; | |
| } | |
| div[data-testid="stChatMessageAvatarAssistant"] { | |
| color: #a192fc; | |
| background: rgb(38, 39, 48); | |
| } | |
| div[data-testid="stChatMessageAvatarUser"] { | |
| color: #e492fc; | |
| background: rgb(38, 39, 48); | |
| } | |
| [data-testid="stChatMessage"][aria-label*="user"], | |
| [data-testid="stChatMessage"]:has([data-testid="stChatMessageAvatarUser"]) { | |
| background-color: rgb(38, 39, 48); | |
| color: black; | |
| margin-left: auto; | |
| text-align: right; | |
| border-radius: 18px 18px 0 18px; | |
| box-shadow: 0 2px 6px rgba(0,0,0,0.1); | |
| } | |
| [data-testid="stChatMessage"][aria-label*="assistant"], | |
| [data-testid="stChatMessage"]:has([data-testid="stChatMessageAvatarAssistant"]) { | |
| background-color: rgb(38, 39, 48); | |
| color: black; | |
| margin-right: auto; | |
| text-align: left; | |
| border-radius: 18px 18px 18px 0; | |
| box-shadow: 0 2px 6px rgba(0,0,0,0.1); | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Constants | |
| WEBHOOK_URL = "https://shahrukh1472.app.n8n.cloud/webhook/2f9e9f00-7ce8-485e-bd34-0df1014c4303" | |
| BEARER_TOKEN = "TestCreds99" | |
| def generate_session_id(): | |
| return str(uuid.uuid4()) | |
| def send_message_to_llm(session_id, message): | |
| headers = { | |
| "Authorization": f"Bearer {BEARER_TOKEN}", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "sessionId": session_id, | |
| "chatInput": message | |
| } | |
| response = requests.post(WEBHOOK_URL, json=payload, headers=headers) | |
| if response.status_code == 200: | |
| return response.json()["output"] | |
| else: | |
| return f"Error: {response.status_code} - {response.text}" | |
| def main(): | |
| st.sidebar.title("π Navigation") | |
| page = st.sidebar.radio("", ["Chatbot", "Information"]) | |
| if page == "Chatbot": | |
| st.title("Hey, I'm your Real-estate AI Agent. Let's Chat!") | |
| st.caption("Your smart assistant for finding the perfect property β faster, easier, smarter.") | |
| # Initialize session state | |
| if "messages" not in st.session_state: | |
| st.session_state.messages = [] | |
| if "session_id" not in st.session_state: | |
| st.session_state.session_id = generate_session_id() | |
| # Display chat messages | |
| for message in st.session_state.messages: | |
| with st.chat_message(message["role"]): | |
| st.write(message["content"]) | |
| # User input | |
| user_input = st.chat_input("Type your message here...") | |
| if user_input: | |
| # Add user message to chat history | |
| st.session_state.messages.append({"role": "user", "content": user_input}) | |
| with st.chat_message("user"): | |
| st.write(user_input) | |
| # Get LLM response | |
| llm_response = send_message_to_llm(st.session_state.session_id, user_input) | |
| # Add LLM response to chat history | |
| st.session_state.messages.append({"role": "assistant", "content": llm_response}) | |
| with st.chat_message("assistant"): | |
| st.write(llm_response) | |
| elif page == "Information": | |
| st.title("About the Real Estate Chatbot") | |
| st.markdown(""" | |
| ### π€ **What This Chatbot Does** | |
| This AI chatbot helps you: | |
| - ποΈ Find properties that match your preferences | |
| - π° Compare price trends in different locations | |
| - π Analyze market growth and investment potential | |
| - π Get instant answers to real estate queries | |
| ### π **Future Additions** | |
| - Integration with live property listings | |
| - Predictive price estimation | |
| - Neighborhood insights and amenities | |
| --- | |
| π¬ *Switch to the Chatbot page from the sidebar to start talking!* | |
| """) | |
| if __name__ == "__main__": | |
| main() |