CoolFace
Apppublic

Tuana/pubmed-qa-mixtral-haystack

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py57 linesDownload Raw Back to root
1 2from json import JSONDecodeError3import logging4from markdown import markdown5import requests6 7import streamlit as st8 9from utils.haystack import query, start_haystack10from utils.ui import reset_results, set_initial_state, sidebar11 12set_initial_state()13 14sidebar()15 16st.write("# ๐Ÿค What have they been posting about lately on Mastodon?")17 18if st.session_state.get("HUGGING_FACE_TOKEN"):19    pipeline = start_haystack(st.session_state.get("HUGGING_FACE_TOKEN"))20    st.session_state["api_key_configured"] = True21    search_bar, button = st.columns(2)22    # Search bar23    with search_bar: 24        question = st.text_input("Ask a question", on_change=reset_results)25 26    with button: 27        st.write("")28        st.write("")29        run_pressed = st.button("Search posts (toots)")30else:31    st.write("Please provide your OpenAI Key to start using the application")32    st.write("If you are using a smaller screen, open the sidebar from the top left to provide your OpenAI Key ๐Ÿ™Œ")33    34if st.session_state.get("api_key_configured"):35    run_query = (36        run_pressed or question != st.session_state.question37    )38 39    # Get results for query40    if run_query and question:41        reset_results()42        st.session_state.question = question43        with st.spinner("๐Ÿ”Ž"):44            try:45                st.session_state.result = query(question, pipeline)46            except JSONDecodeError as je:47                st.error(48                    "๐Ÿ‘“    An error occurred reading the results. Is the document store working?"49                )    50            except Exception as e:51                logging.exception(e)52                st.error("๐Ÿž    An error occurred during the request.")            53                54    if st.session_state.result:55        reply = st.session_state.result56        st.write(reply[0])57