File size: 1,369 Bytes
a576a00
 
 
 
 
 
 
 
 
 
 
 
 
b797bbf
a576a00
b797bbf
a576a00
b797bbf
9e0a453
14eb3f9
a576a00
b797bbf
9e0a453
 
 
a576a00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

from annotated_text import annotation
from json import JSONDecodeError
import logging
from markdown import markdown

import streamlit as st

from utils.haystack import query
from utils.ui import reset_results, set_initial_state

set_initial_state()

st.write("# 🐀 What have they been tweeting about lately?")

search_bar, button = st.columns(2)
# Search bar
with search_bar: 
    username = st.text_input("Please provide a twitter username", on_change=reset_results)
    openai_token = st.text_input("Please provide your OpenAI token πŸ‘‡ ")

with button: 
    st.write("")
    st.write("")
    run_pressed = st.button("Search tweets")

run_query = (
    run_pressed or username != st.session_state.username
)

# Get results for query
if run_query and username:
    reset_results()
    st.session_state.username = username
    with st.spinner("πŸ”Ž"):
        try:
            st.session_state.result = query(username)
        except JSONDecodeError as je:
            st.error(
                "πŸ‘“    An error occurred reading the results. Is the document store working?"
            )    
        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])