yyyycc commited on
Commit
3f41b2d
·
verified ·
1 Parent(s): 3375964

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -1,21 +1,20 @@
1
  import streamlit as st
2
- from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
3
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
  from llama_index.llms.huggingface import HuggingFaceLLM
 
5
 
6
  st.set_page_config(page_title="llama_index_demo", page_icon="🦜🔗")
7
  st.title("llama_index_demo")
8
 
9
- # Initialize models from Hugging Face Hub
10
  @st.cache_resource
11
  def init_models():
12
- # Embeddings model
13
  embed_model = HuggingFaceEmbedding(
14
- model_name="sentence-transformers/all-mpnet-base-v2"
15
  )
16
  Settings.embed_model = embed_model
17
 
18
- # Language Model
19
  llm = HuggingFaceLLM(
20
  model_name="internlm/internlm2-chat-1_8b",
21
  tokenizer_name="internlm/internlm2-chat-1_8b",
@@ -24,8 +23,7 @@ def init_models():
24
  )
25
  Settings.llm = llm
26
 
27
- # Load documents
28
- documents = SimpleDirectoryReader("data.md").load_data() # Assuming data is in a "data" folder in your app directory
29
  index = VectorStoreIndex.from_documents(documents)
30
  query_engine = index.as_query_engine()
31
 
 
1
  import streamlit as st
2
+ from llama_index.core import VectorStoreIndex, Settings
3
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
  from llama_index.llms.huggingface import HuggingFaceLLM
5
+ from llama_index.core.readers import SimpleReader
6
 
7
  st.set_page_config(page_title="llama_index_demo", page_icon="🦜🔗")
8
  st.title("llama_index_demo")
9
 
10
+ # Initialize models
11
  @st.cache_resource
12
  def init_models():
 
13
  embed_model = HuggingFaceEmbedding(
14
+ model_name="sentence-transformers/all-mpnet-base-v2"
15
  )
16
  Settings.embed_model = embed_model
17
 
 
18
  llm = HuggingFaceLLM(
19
  model_name="internlm/internlm2-chat-1_8b",
20
  tokenizer_name="internlm/internlm2-chat-1_8b",
 
23
  )
24
  Settings.llm = llm
25
 
26
+ documents = SimpleReader().load_data(file_path="./data.md") #load data.md file
 
27
  index = VectorStoreIndex.from_documents(documents)
28
  query_engine = index.as_query_engine()
29