import streamlit as st import asyncio import gradio_client st.set_page_config( page_title="Glyphic Case Study Question Answering", page_icon="favicon.ico", layout="centered", ) def check_password(): """Returns `True` if the user had the correct password.""" def password_entered(): """Checks whether a password entered by the user is correct.""" if st.session_state["password"] == st.secrets["password"]: st.session_state["password_correct"] = True del st.session_state["password"] # don't store password else: st.session_state["password_correct"] = False if "password_correct" not in st.session_state: # First run, show input for password. st.text_input( "Password", type="password", on_change=password_entered, key="password" ) return False elif not st.session_state.get("password_correct"): # Password not correct, show input + error. st.text_input( "Password", type="password", on_change=password_entered, key="password" ) st.error("😕 Password incorrect") return False else: return True async def run_query(question: str): client = gradio_client.Client("https://glyphicai-casestudyqa.hf.space/") answer = client.submit(question, api_name="/predict") answer = answer.result() print(answer) return answer["answer"], answer["source"] # @st.cache_data def get_answer(question: str): response = asyncio.run(run_query(question)) return response[0], f"{response[1]}" DESCRIPTION = """This tool is a demo for allowing you to ask questions over your case studies. The case studies are from [Workable](https://resources.workable.com/tag/customer-stories/), a recruiting software company. When you ask a question, the tool will search for the most relevant case study to the question and then use that to answer you.""" if check_password(): # st.title("Glyphic Case Study Question Answering") col_1, col_2 = st.columns([1, 4]) col_1.image("favicon.ico") col_2.title("Glyphic Case Study Question Answering") st.markdown(DESCRIPTION, unsafe_allow_html=True) question = st.text_input("Enter your question") if st.button("Get Answer"): answer, source = get_answer(question) st.subheader("Answer:") st.write(answer) st.subheader("Source:") st.write(source)