maclenn77 commited on
Commit
bef36b3
·
unverified ·
1 Parent(s): bc723d2

Add minor changes (#14)

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -34,6 +34,11 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
34
  if "api_message" not in st.session_state:
35
  st.session_state.api_message = gm.api_message(openai.api_key)
36
 
 
 
 
 
 
37
  # Sidebar
38
  with st.sidebar:
39
  st.write("## OpenAI API key")
@@ -66,16 +71,24 @@ with st.sidebar:
66
  key="temperature",
67
  )
68
 
69
-
70
- # Build settings
71
- chroma_db = ChromaDB(openai.api_key)
72
- openai_client, collection = settings.build(chroma_db)
 
 
 
73
 
74
  # Main
75
- st.title("PDF Explainer")
76
  st.subheader("Create your knowledge base")
77
- st.write("Upload PDF files that will help the AI Agent to understand your domain.")
78
- pdf = st.file_uploader("Upload a file", type="pdf")
 
 
 
 
 
79
 
80
  if pdf is not None:
81
  with fitz.open(stream=pdf.read(), filetype="pdf") as doc: # open document
@@ -95,11 +108,13 @@ if pdf is not None:
95
  ids=[pdf.name + str(idx)],
96
  )
97
  else:
98
- st.write("Please upload a file of type: pdf")
 
 
99
 
100
- st.subheader("Search on your knowledge base")
101
 
102
- prompt = st.chat_input()
103
 
104
  if prompt:
105
  # Create Agent
@@ -118,8 +133,8 @@ if prompt:
118
  except Exception: # pylint: disable=broad-exception-caught
119
  st.warning("Missing OpenAI API Key.")
120
 
121
- st.chat_message("user").write(prompt)
122
- with st.chat_message("assistant"):
123
  st_callback = StreamlitCallbackHandler(st.container())
124
  response = agent.run(prompt, callbacks=[st_callback])
125
- st.write(response)
 
34
  if "api_message" not in st.session_state:
35
  st.session_state.api_message = gm.api_message(openai.api_key)
36
 
37
+
38
+ # Build settings
39
+ chroma_db = ChromaDB(openai.api_key)
40
+ openai_client, collection = settings.build(chroma_db)
41
+
42
  # Sidebar
43
  with st.sidebar:
44
  st.write("## OpenAI API key")
 
71
  key="temperature",
72
  )
73
 
74
+ if st.button("Delete collection"):
75
+ st.warning("Are you sure?")
76
+ if st.button("Yes"):
77
+ try:
78
+ chroma_db.delete_collection(collection.name)
79
+ except AttributeError:
80
+ st.error("Collection erased.")
81
 
82
  # Main
83
+ st.title("GnosisPages")
84
  st.subheader("Create your knowledge base")
85
+
86
+ ## Uploader
87
+ container = st.container()
88
+ container.write(
89
+ "Upload, extract and consult the content of PDF Files for builiding your knowledge base!"
90
+ )
91
+ pdf = container.file_uploader("Upload a file", type="pdf")
92
 
93
  if pdf is not None:
94
  with fitz.open(stream=pdf.read(), filetype="pdf") as doc: # open document
 
108
  ids=[pdf.name + str(idx)],
109
  )
110
  else:
111
+ container.write("Please upload a file of type: pdf")
112
+
113
+ st.subheader("Consult your knowledge base")
114
 
115
+ chatbox = st.container()
116
 
117
+ prompt = chatbox.chat_input()
118
 
119
  if prompt:
120
  # Create Agent
 
133
  except Exception: # pylint: disable=broad-exception-caught
134
  st.warning("Missing OpenAI API Key.")
135
 
136
+ chatbox.chat_message("user").write(prompt)
137
+ with chatbox.chat_message("assistant"):
138
  st_callback = StreamlitCallbackHandler(st.container())
139
  response = agent.run(prompt, callbacks=[st_callback])
140
+ chatbox.write(response)