MuskanZehra5 commited on
Commit
bb8834c
·
verified ·
1 Parent(s): e529da5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +58 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,59 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()