Samarth991's picture
Update app.py
13b91f3 verified
raw
history blame
1.55 kB
import streamlit as st
from QA_Bot import QA_Bot
from PDF_Reader import PDF_4_QA
from PIL import Image
from pathlib import Path
# Streamlit app
def main():
st.session_state.disabled = False
st.session_state.visibility = "visible"
# Page config
st.set_page_config(page_title="Q&A ChatBot",
layout="wide"
)
st.sidebar.title("Upload PDF")
st.sidebar.write("Download Demo PDF file from Below....")
with open("docs/SamarthTandon_cv_2.pdf", "rb") as file:
btn = st.sidebar.download_button(
label="Download PDF",
data=file,
file_name="SamarthTandon_cv_2.pdf"
)
uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type="pdf")
api_input = st.sidebar.text_input(
"Enter The API KEY πŸ‘‡",
label_visibility=st.session_state.visibility,
disabled=st.session_state.disabled,
type="password"
)
if uploaded_file is not None:
save_folder = 'docs/'
save_path = Path(save_folder, uploaded_file.name)
print(save_path)
with open(save_path, mode='wb') as w:
w.write(uploaded_file.getvalue())
st.sidebar.success("File uploaded successfully.")
print(save_path)
vector_store = PDF_4_QA(save_path)
QA_Bot(vector_store,api_input)
# else:
# vector_store = PDF_4_QA("docs/SamarthTandon_cv_2.pdf")
# QA_Bot(vector_store,api_input)
if __name__ == '__main__':
main()