File size: 1,216 Bytes
dbb0a0b
 
 
b50f20a
 
132b796
b50f20a
 
dbb0a0b
 
 
 
 
 
 
 
b50f20a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132b796
b50f20a
 
 
 
 
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
import os
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")

import weave

import streamlit as st
from rag.rag import SimpleRAGPipeline

st.set_page_config(page_title="Chat with the Llama 3 paper!", page_icon="πŸ¦™", layout="centered", initial_sidebar_state="auto", menu_items=None)

wandb_api_key = st.sidebar.text_input('WANDB_API_KEY', type='password')
if len(wandb_api_key)>=10:
    os.environ["WANDB_API_KEY"] = wandb_api_key
else:
    st.stop()

WANDB_PROJECT = "paper_reader"

weave.init(f"{WANDB_PROJECT}")

st.title("Chat with the Llama 3 paper πŸ’¬πŸ¦™")

@st.cache_resource(show_spinner=False)
def load_rag_pipeline():
    rag_pipeline = SimpleRAGPipeline()
    rag_pipeline.build_query_engine()

    return rag_pipeline

if "rag_pipeline" not in st.session_state.keys():
    st.session_state.rag_pipeline = load_rag_pipeline()

rag_pipeline = st.session_state["rag_pipeline"]


def generate_response(query):
    response = rag_pipeline.predict(query)
    st.write_stream(response.response_gen)

with st.form('my_form'):
    query = st.text_area('Ask your question about the Llama 3 paper here:')
    submitted = st.form_submit_button('Submit')
    if submitted:
        generate_response(query)