deven367 commited on
Commit
0b98105
·
1 Parent(s): 08fc1c9

pretify output

Browse files
Files changed (1) hide show
  1. app.py +39 -16
app.py CHANGED
@@ -1,7 +1,14 @@
1
  import os
2
 
 
3
  import requests
4
  import streamlit as st
 
 
 
 
 
 
5
 
6
  try:
7
  from dotenv import load_dotenv
@@ -10,7 +17,6 @@ except ImportError:
10
  pass
11
 
12
 
13
- from responses import SubmitQuestionAndDocumentsResponse
14
 
15
  st.set_page_config(layout="wide")
16
 
@@ -22,35 +28,37 @@ else:
22
 
23
  def make_sidebar():
24
  with st.sidebar:
25
- st.title("Sidebar")
26
- st.write("This is a sidebar.")
27
- st.write("You can add widgets here")
 
 
 
 
28
 
29
  def create_payload(question, documents):
 
30
  payload = {"question": question, "documents": documents}
31
  return payload
32
 
33
 
34
  def main():
35
- st.title("Hello, World!")
36
  # print("Hello, World!")
37
  make_sidebar()
38
 
39
- col1, col2 = st.columns(2)
40
 
41
  with col1:
42
- st.write("This is column 1")
43
- documents = st.multiselect(
44
- "Select the options",
45
- [
46
- "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240314_104111.txt",
47
- "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240315_104111.txt",
48
- "https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240316_104111.txt",
49
- ],
50
  )
51
 
52
  with col2:
53
- st.write("This is column 2")
54
  question = st.text_input(
55
  "Ask the question", value="What product design decisions did the team make?"
56
  )
@@ -73,7 +81,22 @@ def main():
73
  url_local_get = f"{BASE_URL}/get_question_and_facts/"
74
  resp = requests.get(url_local_get)
75
  # st.write(resp.status_code)
76
- st.write(resp.json())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
 
79
  if __name__ == "__main__":
 
1
  import os
2
 
3
+ import nltk
4
  import requests
5
  import streamlit as st
6
+ from nltk.tokenize import sent_tokenize
7
+
8
+ from responses import SubmitQuestionAndDocumentsResponse
9
+
10
+ if not nltk.data.find("tokenizers/punkt"):
11
+ nltk.download("punkt")
12
 
13
  try:
14
  from dotenv import load_dotenv
 
17
  pass
18
 
19
 
 
20
 
21
  st.set_page_config(layout="wide")
22
 
 
28
 
29
  def make_sidebar():
30
  with st.sidebar:
31
+ # st.title("Sidebar")
32
+ # st.write("This is a sidebar.")
33
+ # st.write("You can add widgets here")
34
+ st.write("This functionality is not implemented yet, but it is a placeholder for future use.")
35
+ st.write("It can be easily implemented to select the model to use for the question answering task.")
36
+ _ = st.selectbox("Select the model", ["GPT-4", "Claude Opus"], disabled=True)
37
+
38
 
39
  def create_payload(question, documents):
40
+ documents = documents.split(",")
41
  payload = {"question": question, "documents": documents}
42
  return payload
43
 
44
 
45
  def main():
46
+ st.title("Deven's Cleric Assignment")
47
  # print("Hello, World!")
48
  make_sidebar()
49
 
50
+ col1, col2 = st.columns([1,1])
51
 
52
  with col1:
53
+ # st.write("This is column 1")
54
+ documents = st.text_area(
55
+ "Enter the URLs of the documents (separated by commas)",
56
+ value="https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240314_104111.txt, \
57
+ https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240315_104111.txt"
 
 
 
58
  )
59
 
60
  with col2:
61
+ # st.write("This is column 2")
62
  question = st.text_input(
63
  "Ask the question", value="What product design decisions did the team make?"
64
  )
 
81
  url_local_get = f"{BASE_URL}/get_question_and_facts/"
82
  resp = requests.get(url_local_get)
83
  # st.write(resp.status_code)
84
+ fact_str = ""
85
+ if resp.status_code == 200:
86
+ # st.write(resp.json())
87
+ facts = resp.json()["facts"]
88
+ st.write("Facts:")
89
+ # st.write(len(facts), type(facts))
90
+ # facts = sent_tokenize(facts)
91
+ for i, fact in enumerate(facts):
92
+ if len(fact) > 0:
93
+ fact = fact.replace("$", f"{chr(92)}$")
94
+ sentences = sent_tokenize(fact)
95
+ for sentence in sentences:
96
+ fact_str += f"""1. {sentence}\n"""
97
+
98
+ st.markdown(fact_str)
99
+
100
 
101
 
102
  if __name__ == "__main__":