haylit / app.py
sabatale's picture
Update app.py
0373920 verified
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")
st.session_state["api_key_configured"] = True
st.caption("Example 1 - I see negative comments for my number! they're lies, how do I remove them?")
st.caption("Example 2 - I'm free user and i see there is a Mr. Number Premium thing. What do I get?")
st.caption("Example 3 - 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, start_haystack(st.session_state.get("COHERE_API_KEY")))
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:
llm = st.session_state.result
st.write(llm)