File size: 2,474 Bytes
ab283a4
b64d788
 
ab283a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b64d788
ab283a4
 
 
 
 
 
 
 
 
 
b64d788
 
 
 
 
 
 
ab283a4
b64d788
 
 
67f7d43
ab283a4
 
 
 
 
 
 
 
eb26f08
 
 
 
ab283a4
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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)