Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
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"
|
| 8 |
-
|
| 9 |
-
def generate_session_id():
|
| 10 |
-
return str(uuid.uuid4())
|
| 11 |
-
|
| 12 |
-
def send_message_to_llm(session_id, message):
|
| 13 |
-
headers = {
|
| 14 |
-
"Authorization": f"Bearer {BEARER_TOKEN}",
|
| 15 |
-
"Content-Type": "application/json"
|
| 16 |
-
}
|
| 17 |
-
payload = {
|
| 18 |
-
"sessionId": session_id,
|
| 19 |
-
"chatInput": message
|
| 20 |
-
}
|
| 21 |
-
response = requests.post(WEBHOOK_URL, json=payload, headers=headers)
|
| 22 |
-
if response.status_code == 200:
|
| 23 |
-
return response.json()["output"]
|
| 24 |
-
else:
|
| 25 |
-
return f"Error: {response.status_code} - {response.text}"
|
| 26 |
-
|
| 27 |
-
def main():
|
| 28 |
-
st.title("Hey, I'm your Real-estate AI Agent. Let's Chat!")
|
| 29 |
-
|
| 30 |
-
# Initialize session state
|
| 31 |
-
if "messages" not in st.session_state:
|
| 32 |
-
st.session_state.messages = []
|
| 33 |
-
if "session_id" not in st.session_state:
|
| 34 |
-
st.session_state.session_id = generate_session_id()
|
| 35 |
-
|
| 36 |
-
# Display chat messages
|
| 37 |
-
for message in st.session_state.messages:
|
| 38 |
-
with st.chat_message(message["role"]):
|
| 39 |
-
st.write(message["content"])
|
| 40 |
-
|
| 41 |
-
# User input
|
| 42 |
-
user_input = st.chat_input("Type your message here...")
|
| 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 |
-
# Get LLM response
|
| 51 |
-
llm_response = send_message_to_llm(st.session_state.session_id, user_input)
|
| 52 |
-
|
| 53 |
-
# Add LLM response to chat history
|
| 54 |
-
st.session_state.messages.append({"role": "assistant", "content": llm_response})
|
| 55 |
-
with st.chat_message("assistant"):
|
| 56 |
-
st.write(llm_response)
|
| 57 |
-
|
| 58 |
-
if __name__ == "__main__":
|
| 59 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|