EstherGupta commited on
Commit
fe16fd6
1 Parent(s): 80b1710

Main streamlit app

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from llama_index.llms.replicate import Replicate
4
+ from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
5
+ from llama_index.core.settings import Settings
6
+ from langchain.embeddings.huggingface import HuggingFaceBgeEmbeddings
7
+
8
+
9
+ os.environ["REPLICATE_API_TOKEN"] = st.secrets.replicate_key
10
+
11
+ st.header("Why Can't We All Just Get Along Chatbot")
12
+
13
+ @st.cache_resource(show_spinner=False)
14
+ def load_data():
15
+ with st.spinner(text="Loading and indexing Henry and Fry's chapter – hang tight! This should take 1-2 minutes."):
16
+ llm = Replicate(model="a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5")
17
+ Settings.llm = llm
18
+
19
+ Settings.embed_model = HuggingFaceBgeEmbeddings(model_name="BAAI/bge-base-en")
20
+
21
+ documents = SimpleDirectoryReader("/Users/es26698/Documents/Book_Club/book_chapter/").load_data()
22
+
23
+ index = VectorStoreIndex.from_documents(documents,)
24
+
25
+ return index
26
+
27
+ index = load_data()
28
+
29
+
30
+ query_engine = index.as_query_engine()
31
+ prompt = st.text_input('Enter your question here:', 'Your question...')
32
+
33
+ if st.button('Submit Query'):
34
+ with st.spinner("Generating response... this may take a few minutes..."):
35
+ resp = query_engine.query(prompt)
36
+ st.write(resp.response)