maclenn77 commited on
Commit
0c0e0a0
·
unverified ·
1 Parent(s): 094cc8d

fix: Error cuased by container (#15)

Browse files
Files changed (5) hide show
  1. app.py +9 -10
  2. requirements.txt +1 -1
  3. src/agent.py +1 -1
  4. src/openai_client.py +0 -13
  5. src/settings.py +1 -3
app.py CHANGED
@@ -37,7 +37,7 @@ if "api_message" not in st.session_state:
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:
@@ -84,11 +84,11 @@ 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,13 +108,12 @@ if pdf is not None:
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,8 +132,8 @@ if prompt:
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)
 
37
 
38
  # Build settings
39
  chroma_db = ChromaDB(openai.api_key)
40
+ collection = settings.build(chroma_db)
41
 
42
  # Sidebar
43
  with st.sidebar:
 
84
  st.subheader("Create your knowledge base")
85
 
86
  ## Uploader
87
+
88
+ st.write(
89
  "Upload, extract and consult the content of PDF Files for builiding your knowledge base!"
90
  )
91
+ pdf = st.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
+ st.write("Please upload a file of type: pdf")
112
 
113
  st.subheader("Consult your knowledge base")
114
 
 
115
 
116
+ prompt = st.chat_input()
117
 
118
  if prompt:
119
  # Create Agent
 
132
  except Exception: # pylint: disable=broad-exception-caught
133
  st.warning("Missing OpenAI API Key.")
134
 
135
+ st.chat_message("user").write(prompt)
136
+ with st.chat_message("assistant"):
137
  st_callback = StreamlitCallbackHandler(st.container())
138
  response = agent.run(prompt, callbacks=[st_callback])
139
+ st.write(response)
requirements.txt CHANGED
@@ -3,7 +3,7 @@ tiktoken
3
  langchain
4
  pymupdf
5
  pypdf
6
- duckduckgo-search
7
  chromadb>='0.4.18'
8
  sentence_transformers
9
  streamlit
 
3
  langchain
4
  pymupdf
5
  pypdf
6
+ wikipedia
7
  chromadb>='0.4.18'
8
  sentence_transformers
9
  streamlit
src/agent.py CHANGED
@@ -14,7 +14,7 @@ class PDFExplainer:
14
  self.tools = [
15
  Tool.from_function(
16
  func=search.run,
17
- name="Search DB",
18
  description="Useful when you need more context for answering a question.",
19
  handle_parsing_errors=True,
20
  )
 
14
  self.tools = [
15
  Tool.from_function(
16
  func=search.run,
17
+ name="Search on ChromaDB",
18
  description="Useful when you need more context for answering a question.",
19
  handle_parsing_errors=True,
20
  )
src/openai_client.py DELETED
@@ -1,13 +0,0 @@
1
- """OpenAI client creator."""
2
- import os
3
- from openai import OpenAI
4
-
5
-
6
- def create_client(api_key=None):
7
- """Create an OpenAI client."""
8
- if os.getenv("OPENAI_API_KEY"):
9
- api_key = os.getenv("OPENAI_API_KEY")
10
-
11
- client = OpenAI(api_key=api_key)
12
-
13
- return client
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/settings.py CHANGED
@@ -1,10 +1,8 @@
1
  """Build settings for the app."""
2
- from src.openai_client import create_client
3
 
4
 
5
  def build(chroma_db):
6
  """Build the app."""
7
- openai_client = create_client(chroma_db.api_key)
8
  collection = chroma_db.create_collection("pdf-explainer")
9
 
10
- return openai_client, collection
 
1
  """Build settings for the app."""
 
2
 
3
 
4
  def build(chroma_db):
5
  """Build the app."""
 
6
  collection = chroma_db.create_collection("pdf-explainer")
7
 
8
+ return collection