Update app.py
Browse filesCPU-compatible version of Mistral 7B
app.py
CHANGED
|
@@ -44,33 +44,30 @@ warnings.filterwarnings('ignore')
|
|
| 44 |
# return watsonx_llm
|
| 45 |
|
| 46 |
def get_llm():
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 58 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 59 |
-
model_id,
|
| 60 |
-
quantization_config=quantization_config,
|
| 61 |
-
device_map='cpu',
|
| 62 |
-
torch_dtype='float32',
|
| 63 |
)
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
temperature=
|
| 70 |
-
|
|
|
|
| 71 |
)
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
| 74 |
|
| 75 |
## Document loader
|
| 76 |
def document_loader(file):
|
|
@@ -156,4 +153,4 @@ rag_application = gr.Interface(
|
|
| 156 |
description = 'Upload a PDF document and ask any question. The chatbot will try to answer using the provided document.'
|
| 157 |
)
|
| 158 |
# Launch the app
|
| 159 |
-
rag_application.launch(
|
|
|
|
| 44 |
# return watsonx_llm
|
| 45 |
|
| 46 |
def get_llm():
|
| 47 |
+
mglobal LLM_INSTANCE
|
| 48 |
+
if LLM_INSTANCE is not None:
|
| 49 |
+
return LLM_INSTANCE
|
| 50 |
+
|
| 51 |
+
# Download quantized GGUF model (works on CPU)
|
| 52 |
+
model_path = hf_hub_download(
|
| 53 |
+
repo_id="TheBloke/Mistral-7B-Instruct-v0.3-GGUF",
|
| 54 |
+
filename="mistral-7b-instruct-v0.3.Q4_K_M.gguf",
|
| 55 |
+
local_dir=".",
|
| 56 |
+
local_dir_use_symlinks=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
+
llm = LlamaCpp(
|
| 60 |
+
model_path=model_path,
|
| 61 |
+
n_ctx=4096,
|
| 62 |
+
n_threads=4,
|
| 63 |
+
temperature=0.3,
|
| 64 |
+
top_p=0.9,
|
| 65 |
+
verbose=False,
|
| 66 |
)
|
| 67 |
+
|
| 68 |
+
LLM_INSTANCE = llm
|
| 69 |
+
return llm
|
| 70 |
+
|
| 71 |
|
| 72 |
## Document loader
|
| 73 |
def document_loader(file):
|
|
|
|
| 153 |
description = 'Upload a PDF document and ask any question. The chatbot will try to answer using the provided document.'
|
| 154 |
)
|
| 155 |
# Launch the app
|
| 156 |
+
rag_application.launch()
|