File size: 1,546 Bytes
dc3f654
 
 
 
9935cb6
dc3f654
9935cb6
 
 
dc3f654
 
9935cb6
dc3f654
9935cb6
 
 
 
 
 
dc3f654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9935cb6
dc3f654
 
 
 
9935cb6
dc3f654
9935cb6
dc3f654
9935cb6
 
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
import streamlit as st
from api_call_module import get_answer

processes = ["Praksa", "Izrada završnog rada"]
answers_key = "answers"

# Session init
if answers_key not in st.session_state:
    st.session_state[answers_key] = []


# Save the answer to session
def save_answer(answer: str) -> None:
    st.session_state[answers_key].append(answer)


# Clears the session
def clear_session() -> None:
    st.session_state[answers_key] = []


# Submits the query and saves the answer
def submit_query() -> None:
    if query == "":
        return

    ans = get_answer(query, process)

    save_answer("A: " + ans)
    save_answer("Q: " + query)
    save_answer("**Question {}**")
    save_answer("")


# Sidebar
with st.sidebar:
    st.title("Set up your chatbot!")
    process = st.selectbox("Select a process", processes)
    st.caption("You can find this chatbot implementation [here](https://huggingface.co/spaces/rkrstacic/"
               "Software-module-for-answering-questions-on-processes/tree/main)")

# Main
st.title("Welcome to the process answering chatbot!")
query = st.text_input("Ask me a question", placeholder="e.g. Koliko traje proces prakse?")

# Buttons
col1, col2 = st.columns([6, 1])
col1.button("Send", on_click=submit_query)
col2.button("Clear chat", on_click=clear_session)

# Chat history
with st.expander("Chat History", expanded=True):
    for index, ans in enumerate(st.session_state[answers_key][::-1]):
        st.write(ans if index % 4 != 1 else ans.format((len(st.session_state[answers_key]) - index) // 4 + 1))