|
|
|
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 - How much does it cost to start a Pattern website?") |
|
st.caption("Example 2 - I'm on the app but i can't find how to add attributes to my listing!!? help") |
|
st.caption("Example 3 - A buyer wants to know when I restock items, is that possible?") |
|
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"): |
|
|
|
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) |
|
|