Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from threading import Thread
|
|
|
2 |
from llama_cpp import Llama
|
3 |
import torch
|
4 |
import gradio as gr
|
@@ -14,11 +15,26 @@ from langchain.chains import RetrievalQA
|
|
14 |
from langchain.vectorstores import FAISS
|
15 |
from langchain.embeddings import HuggingFaceEmbeddings
|
16 |
from langchain.prompts import PromptTemplate
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
torch_device = "cuda" if torch.cuda.is_available() else "cpu"
|
19 |
print("Running on device:", torch_device)
|
20 |
print("CPU threads:", torch.get_num_threads())
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
llm = LlamaCpp(
|
24 |
model_path='Llama-2-ko-7B-chat-gguf-q4_0.bin',
|
@@ -34,6 +50,14 @@ llm = LlamaCpp(
|
|
34 |
# ์๋ฒ ๋ฉ ๋ชจ๋ธ ๋ก๋
|
35 |
embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-large")
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# faiss_db ๋ก ๋ก์ปฌ์ ๋ก๋ํ๊ธฐ
|
38 |
docsearch = FAISS.load_local("faiss_db", embeddings)
|
39 |
|
|
|
1 |
from threading import Thread
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
from llama_cpp import Llama
|
4 |
import torch
|
5 |
import gradio as gr
|
|
|
15 |
from langchain.vectorstores import FAISS
|
16 |
from langchain.embeddings import HuggingFaceEmbeddings
|
17 |
from langchain.prompts import PromptTemplate
|
18 |
+
from langchain.text_splitter import CharacterTextSplitter
|
19 |
+
from langchain.document_loaders import PyPDFLoader
|
20 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
21 |
+
from langchain.vectorstores import FAISS
|
22 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
23 |
|
24 |
torch_device = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
print("Running on device:", torch_device)
|
26 |
print("CPU threads:", torch.get_num_threads())
|
27 |
|
28 |
+
loader = PyPDFLoader("total.pdf")
|
29 |
+
pages = loader.load()
|
30 |
+
|
31 |
+
# ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์์ ํ
์คํธ๋ฅผ ์ผ์ ํ ์๋ก ๋๋๊ณ ๊ตฌ๋ถ์๋ก ์ฐ๊ฒฐํ๋ ์์
|
32 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
33 |
+
texts = text_splitter.split_documents(pages)
|
34 |
+
|
35 |
+
print(f"๋ฌธ์์ {len(texts)}๊ฐ์ ๋ฌธ์๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.")
|
36 |
+
|
37 |
+
hf_hub_download(repo_id='StarFox7/Llama-2-ko-7B-chat-gguf', filename='Llama-2-ko-7B-chat-gguf-q4_0.bin', local_dir='./')
|
38 |
|
39 |
llm = LlamaCpp(
|
40 |
model_path='Llama-2-ko-7B-chat-gguf-q4_0.bin',
|
|
|
50 |
# ์๋ฒ ๋ฉ ๋ชจ๋ธ ๋ก๋
|
51 |
embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-large")
|
52 |
|
53 |
+
# ๋ฌธ์์ ์๋ ํ
์คํธ๋ฅผ ์๋ฒ ๋ฉํ๊ณ FAISS ์ ์ธ๋ฑ์ค๋ฅผ ๊ตฌ์ถํจ
|
54 |
+
index = FAISS.from_documents(
|
55 |
+
documents=texts,
|
56 |
+
embedding=embeddings,
|
57 |
+
)
|
58 |
+
|
59 |
+
# faiss_db ๋ก ๋ก์ปฌ์ ์ ์ฅํ๊ธฐ
|
60 |
+
index.save_local("faiss_db")
|
61 |
# faiss_db ๋ก ๋ก์ปฌ์ ๋ก๋ํ๊ธฐ
|
62 |
docsearch = FAISS.load_local("faiss_db", embeddings)
|
63 |
|