aethergroup commited on
Commit
c33079c
·
verified ·
1 Parent(s): c71e7c0

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +29 -2
src/streamlit_app.py CHANGED
@@ -1,9 +1,13 @@
1
  import streamlit as st
2
  import requests
3
  import os
 
 
 
 
4
 
5
  # Get Lambda URL from environment variable
6
- LAMBDA_URL = os.getenv("LAMBDA_URL")
7
  if not LAMBDA_URL:
8
  st.error("LAMBDA_URL environment variable is not set. Please check your .env file.")
9
  st.stop()
@@ -12,6 +16,17 @@ st.set_page_config(page_title="Ask Redshift", page_icon="🤖")
12
 
13
  st.title("🧠 Ask your Redshift Database Anything...")
14
 
 
 
 
 
 
 
 
 
 
 
 
15
  question = st.text_input(
16
  "Enter your question about your data (e.g., 'What is the average cost per lead for March?')"
17
  )
@@ -19,13 +34,25 @@ question = st.text_input(
19
  if st.button("Run Query"):
20
  if question:
21
  with st.spinner("Querying..."):
 
 
 
 
 
 
 
22
  # Call the API
23
  response = requests.post(
24
  LAMBDA_URL,
25
- json={"question": question},
26
  )
27
  response.raise_for_status()
28
  response = response.json()
 
 
 
 
 
29
  st.success(response["answer"])
30
  else:
31
  st.error("Please enter a question.")
 
1
  import streamlit as st
2
  import requests
3
  import os
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
 
9
  # Get Lambda URL from environment variable
10
+ LAMBDA_URL = os.getenv("LAMBDA_URL") or "http://localhost:8000/chats/messages"
11
  if not LAMBDA_URL:
12
  st.error("LAMBDA_URL environment variable is not set. Please check your .env file.")
13
  st.stop()
 
16
 
17
  st.title("🧠 Ask your Redshift Database Anything...")
18
 
19
+ # Initialize conversation_id in session state if not exists
20
+ if "conversation_id" not in st.session_state:
21
+ st.session_state.conversation_id = None
22
+
23
+ # Add system prompt input
24
+ system_prompt = st.text_area(
25
+ "System Prompt (Optional)",
26
+ help="Customize the AI's behavior and instructions. Leave empty to use default behavior.",
27
+ height=100
28
+ )
29
+
30
  question = st.text_input(
31
  "Enter your question about your data (e.g., 'What is the average cost per lead for March?')"
32
  )
 
34
  if st.button("Run Query"):
35
  if question:
36
  with st.spinner("Querying..."):
37
+ # Prepare payload
38
+ payload = {"question": question}
39
+ if st.session_state.conversation_id:
40
+ payload["conversation_id"] = st.session_state.conversation_id
41
+ if system_prompt:
42
+ payload["system_prompt"] = system_prompt
43
+
44
  # Call the API
45
  response = requests.post(
46
  LAMBDA_URL,
47
+ json=payload,
48
  )
49
  response.raise_for_status()
50
  response = response.json()
51
+
52
+ # Store conversation_id for future requests
53
+ if "conversation_id" in response:
54
+ st.session_state.conversation_id = response["conversation_id"]
55
+
56
  st.success(response["answer"])
57
  else:
58
  st.error("Please enter a question.")