CoolFace
Apppublic

CodeYourFuture/sally-explains-things

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py50 linesDownload Raw Back to root
1import streamlit as st2from utils.backend import (get_plain_pipeline, get_retrieval_augmented_pipeline,3                           get_web_retrieval_augmented_pipeline)4from utils.ui import left_sidebar, right_sidebar, main_column5from utils.constants import BUTTON_LOCAL_RET_AUG6 7st.set_page_config(8    page_title="Retrieval Augmentation with Haystack",9    layout="wide"10)11left_sidebar()12 13st.markdown("<center> <h2> Reduce Hallucinations ๐Ÿ˜ตโ€๐Ÿ’ซ with Retrieval Augmentation </h2> </center>", unsafe_allow_html=True)14 15st.markdown("<center>Ask a question about Code Your Future.</center>", unsafe_allow_html=True)16 17col_1, col_2 = st.columns([4, 2], gap="small")18with col_1:19    run_pressed, placeholder_plain_gpt, placeholder_retrieval_augmented = main_column()20 21with col_2:22    right_sidebar()23 24if st.session_state.get('query') and run_pressed:25    ip = st.session_state['query']26    with st.spinner('Loading pipelines... \n This may take a few mins and might also fail if OpenAI API server is down.'):27        p1 = get_plain_pipeline()28    with st.spinner('Fetching answers from plain GPT... '29                    '\n This may take a few mins and might also fail if OpenAI API server is down.'):30        answers = p1.run(ip)31    placeholder_plain_gpt.markdown(answers['results'][0])32 33    if st.session_state.get("query_type", BUTTON_LOCAL_RET_AUG) == BUTTON_LOCAL_RET_AUG:34        with st.spinner(35                'Loading Retrieval Augmented pipeline that can fetch relevant documents from local data store... '36                '\n This may take a few mins and might also fail if OpenAI API server is down.'):37            p2 = get_retrieval_augmented_pipeline()38        with st.spinner('Getting relevant documents from documented stores and calculating answers... '39                        '\n This may take a few mins and might also fail if OpenAI API server is down.'):40            answers_2 = p2.run(ip)41    else:42        with st.spinner(43                'Loading Retrieval Augmented pipeline that can fetch relevant documents from the web... \44                n This may take a few mins and might also fail if OpenAI API server is down.'):45            p3 = get_web_retrieval_augmented_pipeline()46        with st.spinner('Getting relevant documents from the Web and calculating answers... '47                        '\n This may take a few mins and might also fail if OpenAI API server is down.'):48            answers_2 = p3.run(ip)49    placeholder_retrieval_augmented.markdown(answers_2['results'][0])50