from utlis.helper import * initialize_session_state() with st.sidebar: st.image("logo.png", width=170) st.title("AGDC") # Get List of models llms = ['gpt-3.5-turbo', 'gemini'] st.session_state.llm = st.selectbox("Choose LLM",llms) st.session_state.genre = st.radio( "Choose option", ["Select document", "Add document(s)","Delete service(s)", "Delete document(s)"]) if st.session_state.genre=="Add document(s)": st.title('Add Document(s)') # Check service status # Get all available services add_new_service = st.checkbox("Add new service") if add_new_service: new_service = st.text_input("Enter service name") # Get list of Embedding models if new_service and st.button('Add'): add_service(st.session_state.token,new_service) data = {"token": st.session_state.token} json_data = json.dumps(data) headers = {'Content-Type': 'application/json'} services = requests.get(SERVICES_API,data=json_data, headers=headers) services =json.loads(services.text) if len(services)>0: st.session_state.service = st.selectbox("Choose Service",services) if len(services)>0: st.session_state.uploaded_files = st.file_uploader("Upload PDF file", type=["pdf"], accept_multiple_files=False) if st.session_state.uploaded_files: st.session_state.process = st.button('Process') if st.session_state.process: add_document(st.session_state.token,st.session_state.service) elif st.session_state.genre=="Select document": st.title('Scrape Document') data = {"token": st.session_state.token} json_data = json.dumps(data) headers = {'Content-Type': 'application/json'} services = requests.get(SERVICES_API,data=json_data, headers=headers) services =json.loads(services.text) if len(services)>0: st.session_state.service_slected_to_chat = st.selectbox("Choose Service",services) data = {"token": st.session_state.token, "servicename": st.session_state.service_slected_to_chat} json_data = json.dumps(data) headers = {'Content-Type': 'application/json'} history_document = requests.get(DOCUMENT_API,data=json_data, headers=headers) history_document =json.loads(history_document.text).get("documents",[]) history_document = [doc["documentname"] for doc in history_document] st.session_state.doument_slected_to_chat = st.selectbox("Choose Documnet",history_document) data = {"token": st.session_state.token, "service_name": st.session_state.service_slected_to_chat,"document_name":st.session_state.doument_slected_to_chat} json_data = json.dumps(data) headers = {'Content-Type': 'application/json'} number_pages = requests.get(GET_NUM_PAGES,data=json_data, headers=headers) number_pages =json.loads(number_pages.text).get("num_pages") page_options = list(range(1, int(number_pages) + 1)) st.session_state.start_page = st.selectbox("Start Page",page_options) st.session_state.end_page = st.selectbox("End Page", page_options, index=len(page_options) - 1) st.session_state.method = st.selectbox("Chunking Method", ["chunk_per_page", "personalize_chunking"]) if st.session_state.method=="personalize_chunking": st.session_state.split_token = st.text_area("Split Token") else: st.session_state.service_slected_to_chat = None elif st.session_state.genre == "Delete service(s)": st.title('Delete Service(s)') data = {"token": st.session_state.token} json_data = json.dumps(data) headers = {'Content-Type': 'application/json'} services = requests.get(SERVICES_API,data=json_data, headers=headers) services =json.loads(services.text) if len(services)>=2: services.append("ALL") # Get list of documents from histrory if "ALL" in services: service_slected = st.multiselect( "",services ,default="ALL" ) elif len(services)==1: service_slected = st.multiselect( "",services,default=services[0] ) else: service_slected = st.multiselect( "",services ) if "ALL" in service_slected: service_slected = services service_slected.remove("ALL") st.write("You selected:", service_slected) if len(service_slected) > 0: st.session_state.delete = st.button('Delete') if st.session_state.delete: delete_service(st.session_state.token ,service_slected) elif st.session_state.genre == "Delete document(s)": st.title('Delete Document(s)') data = {"token": st.session_state.token} json_data = json.dumps(data) headers = {'Content-Type': 'application/json'} services = requests.get(SERVICES_API,data=json_data, headers=headers) services =json.loads(services.text) if len(services)>0: service = st.selectbox("Choose Service",services) data = {"token": st.session_state.token, "servicename": service} json_data = json.dumps(data) headers = {'Content-Type': 'application/json'} history_document = requests.get(DOCUMENT_API,data=json_data, headers=headers) history_document =json.loads(history_document.text).get("documents",[]) history_document = [doc["documentname"] for doc in history_document] if len(history_document)>=2: history_document.append("ALL") # Get list of documents from histrory if "ALL" in history_document: document_slected_to_delete = st.multiselect( "",history_document ,default="ALL" ) elif len(history_document)==1: document_slected_to_delete = st.multiselect( "",history_document,default=history_document[0] ) else: document_slected_to_delete = st.multiselect( "",history_document ) if "ALL" in document_slected_to_delete: document_slected_to_delete = history_document document_slected_to_delete.remove("ALL") st.write("You selected:", document_slected_to_delete) if len(document_slected_to_delete) > 0: st.session_state.delete = st.button('Delete') if st.session_state.delete: delete_document(st.session_state.token,st.session_state.service ,document_slected_to_delete) css_style = """ """ st.markdown(css_style, unsafe_allow_html=True) with st.container(): st.markdown('