Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,21 +2,21 @@ import streamlit as st
|
|
| 2 |
from api_call_module import get_answer
|
| 3 |
|
| 4 |
processes = ["Praksa", "Izrada završnog rada"]
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
answers = [line.replace("\n", "") for line in open(file_name, "r")]
|
| 11 |
-
except FileNotFoundError:
|
| 12 |
-
open(file_name, "w")
|
| 13 |
|
| 14 |
|
| 15 |
-
# Save the answer to
|
| 16 |
def save_answer(answer: str) -> None:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
# Submits the query and saves the answer
|
|
@@ -32,12 +32,6 @@ def submit_query() -> None:
|
|
| 32 |
save_answer("")
|
| 33 |
|
| 34 |
|
| 35 |
-
# Clears the chat
|
| 36 |
-
def clear() -> None:
|
| 37 |
-
open(file_name, 'w').close()
|
| 38 |
-
pass
|
| 39 |
-
|
| 40 |
-
|
| 41 |
# Sidebar
|
| 42 |
with st.sidebar:
|
| 43 |
st.title("Set up your chatbot!")
|
|
@@ -47,14 +41,14 @@ with st.sidebar:
|
|
| 47 |
|
| 48 |
# Main
|
| 49 |
st.title("Welcome to the process answering chatbot!")
|
| 50 |
-
query = st.text_input("Ask me a question", placeholder="e.g. Koliko traje proces
|
| 51 |
|
| 52 |
# Buttons
|
| 53 |
col1, col2 = st.columns([6, 1])
|
| 54 |
col1.button("Send", on_click=submit_query)
|
| 55 |
-
col2.button("Clear chat", on_click=
|
| 56 |
-
|
| 57 |
|
|
|
|
| 58 |
with st.expander("Chat History", expanded=True):
|
| 59 |
-
for index, ans in enumerate(
|
| 60 |
-
st.write(ans if index % 4 != 1 else ans.format((len(
|
|
|
|
| 2 |
from api_call_module import get_answer
|
| 3 |
|
| 4 |
processes = ["Praksa", "Izrada završnog rada"]
|
| 5 |
+
answers_key = "answers"
|
| 6 |
|
| 7 |
+
# Session init
|
| 8 |
+
if answers_key not in st.session_state:
|
| 9 |
+
st.session_state[answers_key] = []
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
+
# Save the answer to session
|
| 13 |
def save_answer(answer: str) -> None:
|
| 14 |
+
st.session_state[answers_key].append(answer)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Clears the session
|
| 18 |
+
def clear_session() -> None:
|
| 19 |
+
st.session_state[answers_key] = []
|
| 20 |
|
| 21 |
|
| 22 |
# Submits the query and saves the answer
|
|
|
|
| 32 |
save_answer("")
|
| 33 |
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Sidebar
|
| 36 |
with st.sidebar:
|
| 37 |
st.title("Set up your chatbot!")
|
|
|
|
| 41 |
|
| 42 |
# Main
|
| 43 |
st.title("Welcome to the process answering chatbot!")
|
| 44 |
+
query = st.text_input("Ask me a question", placeholder="e.g. Koliko traje proces prakse?")
|
| 45 |
|
| 46 |
# Buttons
|
| 47 |
col1, col2 = st.columns([6, 1])
|
| 48 |
col1.button("Send", on_click=submit_query)
|
| 49 |
+
col2.button("Clear chat", on_click=clear_session)
|
|
|
|
| 50 |
|
| 51 |
+
# Chat history
|
| 52 |
with st.expander("Chat History", expanded=True):
|
| 53 |
+
for index, ans in enumerate(st.session_state[answers_key][::-1]):
|
| 54 |
+
st.write(ans if index % 4 != 1 else ans.format((len(st.session_state[answers_key]) - index) // 4 + 1))
|