Spaces:
Runtime error
Runtime error
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)) | |