AI-RESEARCHER-2024
commited on
Commit
•
0ddbfad
1
Parent(s):
5d14fe6
Update app.py
Browse files
app.py
CHANGED
@@ -2,21 +2,31 @@ import os
|
|
2 |
import gradio as gr
|
3 |
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
|
4 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
5 |
-
from llama_index.llms.
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
os.system('sleep 5')
|
11 |
-
os.system('ollama pull llama3.2')
|
12 |
-
os.system('ollama pull llama3.2')
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Initialize embeddings and LLM
|
15 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-small-en-v1.5")
|
16 |
-
llama = Ollama(
|
17 |
-
model="llama3.2",
|
18 |
-
request_timeout=1000,
|
19 |
-
)
|
20 |
|
21 |
def initialize_index():
|
22 |
"""Initialize the vector store index from PDF files in the data directory"""
|
@@ -34,7 +44,7 @@ def initialize_index():
|
|
34 |
)
|
35 |
|
36 |
# Return query engine with Llama
|
37 |
-
return index.as_query_engine(llm=
|
38 |
|
39 |
# Initialize the query engine at startup
|
40 |
query_engine = initialize_index()
|
|
|
2 |
import gradio as gr
|
3 |
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
|
4 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
5 |
+
from llama_index.llms.llama_cpp import LlamaCPP
|
6 |
+
from llama_index.llms.llama_cpp.llama_utils import (
|
7 |
+
messages_to_prompt,
|
8 |
+
completion_to_prompt,
|
9 |
+
)
|
|
|
|
|
|
|
10 |
|
11 |
+
model_url = 'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf'
|
12 |
+
llm = LlamaCPP(
|
13 |
+
# You can pass in the URL to a GGML model to download it automatically
|
14 |
+
model_url=model_url,
|
15 |
+
temperature=0.1,
|
16 |
+
max_new_tokens=256,
|
17 |
+
context_window=2048,
|
18 |
+
# kwargs to pass to __call__()
|
19 |
+
generate_kwargs={},
|
20 |
+
# kwargs to pass to __init__()
|
21 |
+
# set to at least 1 to use GPU
|
22 |
+
model_kwargs={"n_gpu_layers": 1},
|
23 |
+
# transform inputs into Llama2 format
|
24 |
+
messages_to_prompt=messages_to_prompt,
|
25 |
+
completion_to_prompt=completion_to_prompt,
|
26 |
+
verbose=True,
|
27 |
+
)
|
28 |
# Initialize embeddings and LLM
|
29 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-small-en-v1.5")
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def initialize_index():
|
32 |
"""Initialize the vector store index from PDF files in the data directory"""
|
|
|
44 |
)
|
45 |
|
46 |
# Return query engine with Llama
|
47 |
+
return index.as_query_engine(llm=llm)
|
48 |
|
49 |
# Initialize the query engine at startup
|
50 |
query_engine = initialize_index()
|