Spaces:
Sleeping
Sleeping
Update app.py
Browse files391 unmodified lines3923933943953963973983994004014024034044054064074084094106 unmodified lines417418419420421422423424425426427428429430431432433165 unmodified lines5996006016026036046056066076086096106116125 unmodified lines61861962062162262362462562662762839 unmodified lines668669670671672673674675676677678391 unmodified lineselse:organization_name = st.text_input("What is the name of your organization", "")num_domains = st.number_input("How many datasets do you have uploaded", value=1, step=1, min_value=1, max_value=10)with st.expander("Explain"):st.write("How many datasets did you upload in Step 4) Upload Datasets?")st.divider()domain_info = []for i in range(num_domains):domain_link = st.text_input(f"Please enter link to dataset {i+1} with the format username/dataset_name", "Example: KeshavRa/About_YSA_Database")domain_name = st.text_input(f"What should domain {i+1} be called in the chatbot itself", "Example: About YSA")domain_purpose = st.text_area(f"What is the purpose of domain {i+1}, provide example questions (this will be visible to users of the chatbot)", 'Example: On this page, you can learn about what YSA does, how YSA was started, the advisory board, and the programs we offer.\n\nExample Questions\n\n--> What is the purpose of Youth Spirit Artworks?\n\n--> Who created YSA?\n\n--> What is the Advisory Board for Youth Spirit Artworks?\n\n--> What are the three empowerment-focused program areas of YSA?')domain_instructions = st.text_input(f"What baseline instructions/specifications should be sent to ChatGPT to answer questions in domain {i+1}", "Example: You are an assistant to help the user learn more about Youth Spirit Artworks")domain = {"link": domain_link, "name": domain_name, "purpose": domain_purpose, "instructions": domain_instructions}domain_info.append(domain)st.divider()6 unmodified linesst.session_state.clear()st.session_state.error = "Please enter an organization name"st.rerun()missing_info = []for i in range(len(domain_info)):if domain_info[i]['link'] == "":missing_info.append(f"link to domain {i+1}")if domain_info[i]['name'] == "":missing_info.append(f"name for domain {i+1}")if domain_info[i]['purpose'] == "":missing_info.append(f"purpose for domain {i+1}")if domain_info[i]['instructions'] == "":missing_info.append(f"instructions for domain {i+1}")if missing_info:error = "Missing Info: "for info in missing_info:165 unmodified linesif "curr_domain" not in st.session_state:st.session_state.curr_domain = ""init_messages = {{}}for d in domain_info:init_messages[d['name']] = d['purpose']chatbot_instructions = {{}}for d in domain_info:chatbot_instructions[d['name']] = d['instructions']# Embed and store the first N supports for this demowith st.spinner("Loading, please be patient with us ... ๐"):L = len(dataset["train"]["questions"])5 unmodified lines)if st.session_state.curr_domain != domain:st.session_state.messages = []init_message = init_messages[domain]st.session_state.messages.append({{"role": "assistant", "content": init_message}})st.session_state.curr_domain = domain# Display chat messages from history on app rerun39 unmodified linesengineered_prompt = f'''Based on the context: {{ref_from_db_search}},answer the user question: {{question}}.'''directions = chatbot_instructions[domain]answer = call_chatgpt(engineered_prompt, directions)response = answer# Display assistant response in chat message container391 unmodified lines3923933943953963973983994004014024034044054064076 unmodified lines414415416417418419420421422423424425426427428429430165 unmodified lines5965975985996006015 unmodified lines60760860961061161261339 unmodified lines653654655656657658659660391 unmodified lineselse:organization_name = st.text_input("What is the name of your organization", "")username = st.text_input("What is your HuggingFace username (from Step 4)", "")num_domains = st.number_input("How many datasets do you have uploaded (from Step 4)", value=1, step=1, min_value=1, max_value=10)st.divider()domain_info = []for i in range(num_domains):domain_link = st.text_input(f"Please enter name of dataset {i+1} (from Step 4)", "Example: About_YSA_Database")domain_name = st.text_input(f"What should dataset {i+1} be called in the chatbot itself", "Example: About YSA")domain = {"link": username + domain_link, "name": domain_name}domain_info.append(domain)st.divider()6 unmodified linesst.session_state.clear()st.session_state.error = "Please enter an organization name"st.rerun()if username == "":st.session_state.clear()st.session_state.error = "Please enter a username"st.rerun()missing_info = []for i in range(len(domain_info)):if domain_info[i]['link'] == "":missing_info.append(f"link to domain {i+1}")if domain_info[i]['name'] == "":missing_info.append(f"name for domain {i+1}")if missing_info:error = "Missing Info: "for info in missing_info:165 unmodified linesif "curr_domain" not in st.session_state:st.session_state.curr_domain = ""# Embed and store the first N supports for this demowith st.spinner("Loading, please be patient with us ... ๐"):L = len(dataset["train"]["questions"])5 unmodified lines)if st.session_state.curr_domain != domain:st.session_state.messages = []st.session_state.curr_domain = domain# Display chat messages from history on app rerun39 unmodified linesengineered_prompt = f'''Based on the context: {{ref_from_db_search}},answer the user question: {{question}}.'''answer = call_chatgpt(engineered_prompt, "You are a helpful assistant.")response = answer# Display assistant response in chat message container
app.py+13-31