File size: 4,386 Bytes
d2ec16d
bb8834c
 
 
5d8fc29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb8834c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d8fc29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb8834c
5d8fc29
 
 
 
 
bb8834c
5d8fc29
 
bb8834c
5d8fc29
 
 
 
bb8834c
 
5d8fc29
 
 
 
 
 
 
 
 
bb8834c
5d8fc29
 
 
 
bb8834c
5d8fc29
 
 
 
bb8834c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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()