haylit2 / app.py
sabatale's picture
Update app.py
25af997 verified
raw
history blame
No virus
1.45 kB
from annotated_text import annotation
from json import JSONDecodeError
import logging
from markdown import markdown
import requests
import streamlit as st
from utils.haystack import query, start_haystack
from utils.ui import reset_results, set_initial_state, sidebar
set_initial_state()
sidebar()
st.write("# πŸ”Ž Ask Me Anything")
pipeline = start_haystack(st.session_state.get("COHERE_API_KEY"))
st.session_state["api_key_configured"] = True
st.caption("(e.g., It doesn't work on Android. The app is not blocking calls!!!)")
prompt = st.text_input("Your question", on_change=reset_results)
st.write("")
st.write("")
run_pressed = st.button("Ask")
if st.session_state.get("api_key_configured"):
# Get results for query
if run_pressed and prompt:
reset_results()
st.session_state.prompt = prompt
print(prompt)
with st.spinner("πŸ”Ž"):
try:
st.session_state.result = query(prompt, pipeline)
except JSONDecodeError as je:
st.error(
"πŸ›‘    Something went wrong! Database failure."
)
except Exception as e:
logging.exception(e)
st.error("🐞    An error occurred during the request.")
if st.session_state.result:
voice = st.session_state.result
st.write(voice[0])