Skip to content

Commit

Permalink
Add minor changes (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maclenn77 authored Dec 10, 2023
1 parent bc723d2 commit bef36b3
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def click_wk_button():
if "api_message" not in st.session_state:
st.session_state.api_message = gm.api_message(openai.api_key)


# Build settings
chroma_db = ChromaDB(openai.api_key)
openai_client, collection = settings.build(chroma_db)

# Sidebar
with st.sidebar:
st.write("## OpenAI API key")
Expand Down Expand Up @@ -66,16 +71,24 @@ def click_wk_button():
key="temperature",
)


# Build settings
chroma_db = ChromaDB(openai.api_key)
openai_client, collection = settings.build(chroma_db)
if st.button("Delete collection"):
st.warning("Are you sure?")
if st.button("Yes"):
try:
chroma_db.delete_collection(collection.name)
except AttributeError:
st.error("Collection erased.")

# Main
st.title("PDF Explainer")
st.title("GnosisPages")
st.subheader("Create your knowledge base")
st.write("Upload PDF files that will help the AI Agent to understand your domain.")
pdf = st.file_uploader("Upload a file", type="pdf")

## Uploader
container = st.container()
container.write(
"Upload, extract and consult the content of PDF Files for builiding your knowledge base!"
)
pdf = container.file_uploader("Upload a file", type="pdf")

if pdf is not None:
with fitz.open(stream=pdf.read(), filetype="pdf") as doc: # open document
Expand All @@ -95,11 +108,13 @@ def click_wk_button():
ids=[pdf.name + str(idx)],
)
else:
st.write("Please upload a file of type: pdf")
container.write("Please upload a file of type: pdf")

st.subheader("Consult your knowledge base")

st.subheader("Search on your knowledge base")
chatbox = st.container()

prompt = st.chat_input()
prompt = chatbox.chat_input()

if prompt:
# Create Agent
Expand All @@ -118,8 +133,8 @@ def click_wk_button():
except Exception: # pylint: disable=broad-exception-caught
st.warning("Missing OpenAI API Key.")

st.chat_message("user").write(prompt)
with st.chat_message("assistant"):
chatbox.chat_message("user").write(prompt)
with chatbox.chat_message("assistant"):
st_callback = StreamlitCallbackHandler(st.container())
response = agent.run(prompt, callbacks=[st_callback])
st.write(response)
chatbox.write(response)

0 comments on commit bef36b3

Please sign in to comment.