Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,14 +7,7 @@
|
|
7 |
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
9 |
from langchain.llms import HuggingFaceHub
|
10 |
-
|
11 |
-
|
12 |
-
###### other models:
|
13 |
-
# "Trelis/Llama-2-7b-chat-hf-sharded-bf16"
|
14 |
-
# "bn22/Mistral-7B-Instruct-v0.1-sharded"
|
15 |
-
# "HuggingFaceH4/zephyr-7b-beta"
|
16 |
-
|
17 |
-
# function for loading 4-bit quantized model
|
18 |
def load_model(model_name: str):
|
19 |
|
20 |
model = HuggingFaceHub(
|
@@ -22,23 +15,7 @@ def load_model(model_name: str):
|
|
22 |
model_kwargs={"max_length": 1048, "temperature":0.2, "max_new_tokens":256, "top_p":0.95, "repetition_penalty":1.0},
|
23 |
)
|
24 |
|
25 |
-
|
26 |
-
:param model_name: Name or path of the model to be loaded.
|
27 |
-
:return: Loaded quantized model.
|
28 |
-
|
29 |
-
bnb_config = BitsAndBytesConfig(
|
30 |
-
load_in_4bit=True,
|
31 |
-
bnb_4bit_use_double_quant=True,
|
32 |
-
bnb_4bit_quant_type="nf4",
|
33 |
-
bnb_4bit_compute_dtype=torch.bfloat16
|
34 |
-
)
|
35 |
-
|
36 |
-
model = AutoModelForCausalLM.from_pretrained(
|
37 |
-
model_name,
|
38 |
-
load_in_4bit=True,
|
39 |
-
torch_dtype=torch.bfloat16,
|
40 |
-
quantization_config=bnb_config
|
41 |
-
)"""
|
42 |
return model
|
43 |
|
44 |
##################################################
|
@@ -51,8 +28,7 @@ from langchain_core.messages import AIMessage, HumanMessage
|
|
51 |
from langchain_community.document_loaders import WebBaseLoader
|
52 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
53 |
from langchain_community.vectorstores import Chroma
|
54 |
-
|
55 |
-
#from langchain_openai import OpenAIEmbeddings, ChatOpenAI
|
56 |
from langchain.embeddings import HuggingFaceBgeEmbeddings
|
57 |
from langchain.vectorstores.faiss import FAISS
|
58 |
|
@@ -67,8 +43,8 @@ load_dotenv()
|
|
67 |
|
68 |
from langchain_community.document_loaders import TextLoader
|
69 |
|
70 |
-
def load_txt():
|
71 |
-
loader = TextLoader(
|
72 |
document = loader.load()
|
73 |
# split the document into chunks
|
74 |
text_splitter = RecursiveCharacterTextSplitter()
|
@@ -100,7 +76,7 @@ def load_txt():
|
|
100 |
return vector_store
|
101 |
|
102 |
|
103 |
-
def get_vectorstore_from_url(url):
|
104 |
# get the text in document form
|
105 |
loader = WebBaseLoader(url)
|
106 |
document = loader.load()
|
@@ -216,7 +192,7 @@ def get_response(user_input):
|
|
216 |
|
217 |
|
218 |
#vs = get_vectorstore_from_url(user_url, all_domain)
|
219 |
-
vs = get_vectorstore_from_url(
|
220 |
# print("------ here 22 " )
|
221 |
chat_history =[]
|
222 |
retriever_chain = get_context_retriever_chain(vs)
|
@@ -248,6 +224,7 @@ def get_response(message, history):
|
|
248 |
dialog = history_to_dialog_format(history)
|
249 |
dialog.append({"role": "user", "content": message})
|
250 |
|
|
|
251 |
# Define the prompt as a ChatPromptValue object
|
252 |
#user_input = ChatPromptValue(user_input)
|
253 |
|
|
|
7 |
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
9 |
from langchain.llms import HuggingFaceHub
|
10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def load_model(model_name: str):
|
12 |
|
13 |
model = HuggingFaceHub(
|
|
|
15 |
model_kwargs={"max_length": 1048, "temperature":0.2, "max_new_tokens":256, "top_p":0.95, "repetition_penalty":1.0},
|
16 |
)
|
17 |
|
18 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
return model
|
20 |
|
21 |
##################################################
|
|
|
28 |
from langchain_community.document_loaders import WebBaseLoader
|
29 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
30 |
from langchain_community.vectorstores import Chroma
|
31 |
+
|
|
|
32 |
from langchain.embeddings import HuggingFaceBgeEmbeddings
|
33 |
from langchain.vectorstores.faiss import FAISS
|
34 |
|
|
|
43 |
|
44 |
from langchain_community.document_loaders import TextLoader
|
45 |
|
46 |
+
def load_txt(path="./a.cv.ckaller.2024.txt"):
|
47 |
+
loader = TextLoader(path)
|
48 |
document = loader.load()
|
49 |
# split the document into chunks
|
50 |
text_splitter = RecursiveCharacterTextSplitter()
|
|
|
76 |
return vector_store
|
77 |
|
78 |
|
79 |
+
def get_vectorstore_from_url(url="https://huggingface.co/Chris4K"):
|
80 |
# get the text in document form
|
81 |
loader = WebBaseLoader(url)
|
82 |
document = loader.load()
|
|
|
192 |
|
193 |
|
194 |
#vs = get_vectorstore_from_url(user_url, all_domain)
|
195 |
+
vs = get_vectorstore_from_url()
|
196 |
# print("------ here 22 " )
|
197 |
chat_history =[]
|
198 |
retriever_chain = get_context_retriever_chain(vs)
|
|
|
224 |
dialog = history_to_dialog_format(history)
|
225 |
dialog.append({"role": "user", "content": message})
|
226 |
|
227 |
+
print(dialog)
|
228 |
# Define the prompt as a ChatPromptValue object
|
229 |
#user_input = ChatPromptValue(user_input)
|
230 |
|