deven367 commited on
Commit
17b9280
·
1 Parent(s): 3519d0b

construct url on the fly

Browse files
Files changed (1) hide show
  1. app.py +35 -14
app.py CHANGED
@@ -1,9 +1,19 @@
 
 
1
  import requests
2
  import streamlit as st
 
3
 
4
  from responses import SubmitQuestionAndDocumentsResponse
5
 
6
  st.set_page_config(layout="wide")
 
 
 
 
 
 
 
7
 
8
  def make_sidebar():
9
  with st.sidebar:
@@ -11,23 +21,23 @@ def make_sidebar():
11
  st.write("This is a sidebar.")
12
  st.write("You can add widgets here")
13
 
 
14
  def create_payload(question, logs):
15
- payload = {
16
- "question": question,
17
- "logs": logs
18
- }
19
  # st.write(payload)
20
  return payload
21
 
 
22
  def process_payload(payload):
23
  all_logs = payload["logs"]
24
  text = ""
25
  for log in all_logs:
26
  text += requests.get(log).text
27
 
28
- payload['text'] = text
29
  return payload
30
 
 
31
  def main():
32
  st.title("Hello, World!")
33
  # print("Hello, World!")
@@ -37,15 +47,20 @@ def main():
37
 
38
  with col1:
39
  st.write("This is column 2")
40
- logs = st.multiselect("Select the options",
41
- [
42
- "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240314_104111.txt",
43
- "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240315_104111.txt",
44
- "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240316_104111.txt",])
 
 
 
45
 
46
  with col2:
47
  st.write("This is column 1")
48
- question = st.text_input("Ask the question", value="What product design decisions did the team make?")
 
 
49
 
50
  payload = create_payload(question, logs)
51
  processed_payload = process_payload(payload)
@@ -55,11 +70,17 @@ def main():
55
  st.write(data.model_dump())
56
 
57
  if st.button("Submit"):
58
- url = "https://deven-cleric-backend.onrender.com/submit_question_and_documents/"
59
- url_local = "http://"
60
  resp = requests.post(url, json=data.model_dump())
61
  st.write(resp.status_code)
62
  st.write(resp.json())
63
 
 
 
 
 
 
 
64
  if __name__ == "__main__":
65
- main()
 
1
+ import os
2
+
3
  import requests
4
  import streamlit as st
5
+ from dotenv import load_dotenv
6
 
7
  from responses import SubmitQuestionAndDocumentsResponse
8
 
9
  st.set_page_config(layout="wide")
10
+ load_dotenv()
11
+
12
+ if os.getenv("ENV") == "production":
13
+ BASE_URL = "https://deven-cleric-backend.onrender.com"
14
+ else:
15
+ BASE_URL = "http://localhost:8000"
16
+
17
 
18
  def make_sidebar():
19
  with st.sidebar:
 
21
  st.write("This is a sidebar.")
22
  st.write("You can add widgets here")
23
 
24
+
25
  def create_payload(question, logs):
26
+ payload = {"question": question, "logs": logs}
 
 
 
27
  # st.write(payload)
28
  return payload
29
 
30
+
31
  def process_payload(payload):
32
  all_logs = payload["logs"]
33
  text = ""
34
  for log in all_logs:
35
  text += requests.get(log).text
36
 
37
+ payload["text"] = text
38
  return payload
39
 
40
+
41
  def main():
42
  st.title("Hello, World!")
43
  # print("Hello, World!")
 
47
 
48
  with col1:
49
  st.write("This is column 2")
50
+ logs = st.multiselect(
51
+ "Select the options",
52
+ [
53
+ "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240314_104111.txt",
54
+ "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240315_104111.txt",
55
+ "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240316_104111.txt",
56
+ ],
57
+ )
58
 
59
  with col2:
60
  st.write("This is column 1")
61
+ question = st.text_input(
62
+ "Ask the question", value="What product design decisions did the team make?"
63
+ )
64
 
65
  payload = create_payload(question, logs)
66
  processed_payload = process_payload(payload)
 
70
  st.write(data.model_dump())
71
 
72
  if st.button("Submit"):
73
+ # url = "https://deven-cleric-backend.onrender.com/submit_question_and_documents/"
74
+ url = f"{BASE_URL}/submit_question_and_documents/"
75
  resp = requests.post(url, json=data.model_dump())
76
  st.write(resp.status_code)
77
  st.write(resp.json())
78
 
79
+ url_local_get = f"{BASE_URL}/get_question_and_facts/"
80
+ resp = requests.get(url_local_get)
81
+ st.write(resp.status_code)
82
+ st.write(resp.json())
83
+
84
+
85
  if __name__ == "__main__":
86
+ main()