Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minor changes #14

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading