deven367 commited on
Commit
9f66c8d
·
1 Parent(s): cb40a92

add more cases of error handling

Browse files
Files changed (1) hide show
  1. app.py +56 -34
app.py CHANGED
@@ -37,6 +37,7 @@ def make_sidebar():
37
  st.write("It can be easily implemented to select the model to use for the question answering task.")
38
  _ = st.selectbox("Select the model", ["GPT-4", "Claude Opus"], disabled=True)
39
 
 
40
 
41
  def create_payload(question, documents):
42
  documents = documents.split(",")
@@ -48,6 +49,7 @@ def main():
48
  st.title("Deven's Cleric Assignment")
49
  # print("Hello, World!")
50
  make_sidebar()
 
51
 
52
  col1, col2 = st.columns([1,1])
53
 
@@ -55,49 +57,69 @@ def main():
55
  # st.write("This is column 1")
56
  documents = st.text_area(
57
  "Enter the URLs of the documents (separated by commas)",
58
- value="https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240314_104111.txt, \
59
- https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240315_104111.txt"
60
  )
61
 
62
  with col2:
63
  # st.write("This is column 2")
64
  question = st.text_input(
65
- "Ask the question", value="What product design decisions did the team make?"
 
66
  )
67
 
68
- payload = create_payload(question, documents)
69
-
70
-
71
- data = SubmitQuestionAndDocumentsResponse(**payload)
72
- # on = st.toggle('View model dump', False, key='view_model_dump')
73
- # if on:
74
- # st.write(data.model_dump())
75
 
76
  if st.button("Submit"):
77
- # url = "https://deven-cleric-backend.onrender.com/submit_question_and_documents/"
78
- url = f"{BASE_URL}/submit_question_and_documents/"
79
- resp = requests.post(url, json=data.model_dump())
80
- # st.write(resp.status_code)
81
- # st.write(resp.json())
82
-
83
- url_local_get = f"{BASE_URL}/get_question_and_facts/"
84
- resp = requests.get(url_local_get)
85
- # st.write(resp.status_code)
86
- fact_str = ""
87
- if resp.status_code == 200:
88
- # st.write(resp.json())
89
- facts = resp.json()["facts"]
90
- st.write("Facts:")
91
- # st.write(len(facts), type(facts))
92
- # facts = sent_tokenize(facts)
93
- for i, fact in enumerate(facts):
94
- if len(fact) > 0:
95
- fact = fact.replace("$", f"{chr(92)}$")
96
- sentences = sent_tokenize(fact)
97
- for sentence in sentences:
98
- fact_str += f"""1. {sentence}\n"""
99
-
100
- st.markdown(fact_str)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
 
103
 
 
37
  st.write("It can be easily implemented to select the model to use for the question answering task.")
38
  _ = st.selectbox("Select the model", ["GPT-4", "Claude Opus"], disabled=True)
39
 
40
+ _ = st.text_input("Enter the system prompt for the model", value="You are a helful assistant.", disabled=True)
41
 
42
  def create_payload(question, documents):
43
  documents = documents.split(",")
 
49
  st.title("Deven's Cleric Assignment")
50
  # print("Hello, World!")
51
  make_sidebar()
52
+ documents, question = None, None
53
 
54
  col1, col2 = st.columns([1,1])
55
 
 
57
  # st.write("This is column 1")
58
  documents = st.text_area(
59
  "Enter the URLs of the documents (separated by commas)",
60
+ # value="https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240314_104111.txt, \
61
+ # https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240315_104111.txt"
62
  )
63
 
64
  with col2:
65
  # st.write("This is column 2")
66
  question = st.text_input(
67
+ "Ask the question",
68
+ # value="What product design decisions did the team make?"
69
  )
70
 
 
 
 
 
 
 
 
71
 
72
  if st.button("Submit"):
73
+
74
+ # check if the documents and question are not empty
75
+ if len(documents) > 0 and len(question) > 0:
76
+
77
+ # create the payload
78
+ payload = create_payload(question, documents)
79
+
80
+ # create the data object
81
+ data = SubmitQuestionAndDocumentsResponse(**payload)
82
+
83
+ # submit the question and documents
84
+ url = f"{BASE_URL}/submit_question_and_documents/"
85
+ resp = requests.post(url, json=data.model_dump())
86
+
87
+ # check the response
88
+ if resp.status_code == 200:
89
+ st.write("Question and documents submitted successfully.")
90
+ else:
91
+ st.write("There was an error submitting the question and documents.")
92
+ st.write(resp.status_code)
93
+ st.write(resp.json())
94
+
95
+ url_local_get = f"{BASE_URL}/get_question_and_facts/"
96
+ st.write("Polling the facts...")
97
+
98
+ # get the facts
99
+ resp = requests.get(url_local_get)
100
+ # st.write(resp.status_code)
101
+ fact_str = ""
102
+ if resp.status_code == 200:
103
+ facts = resp.json()["facts"]
104
+
105
+ st.write("Facts:")
106
+ if facts is not None:
107
+ for i, fact in enumerate(facts):
108
+ if len(fact) > 0:
109
+ fact = fact.replace("$", f"{chr(92)}$")
110
+ sentences = sent_tokenize(fact)
111
+ for sentence in sentences:
112
+ fact_str += f"""1. {sentence}\n"""
113
+
114
+ st.markdown(fact_str)
115
+ else:
116
+ st.warning("No facts found. Check the URLs and question and try again.")
117
+ else:
118
+ st.write("There was an error fetching the facts.")
119
+ st.write(resp.status_code)
120
+ st.write(resp.json())
121
+ else:
122
+ st.warning("Please enter a question and documents to proceed.")
123
 
124
 
125