KalooAI commited on
Commit
5bbe733
·
verified ·
1 Parent(s): d19dffa

Update app.py

Browse files

CPU-compatible version of Mistral 7B

Files changed (1) hide show
  1. app.py +22 -25
app.py CHANGED
@@ -44,33 +44,30 @@ warnings.filterwarnings('ignore')
44
  # return watsonx_llm
45
 
46
  def get_llm():
47
- model_id = 'ibm-granite/granite-3.0-8b-instruct'
48
-
49
- # Configuration for 4-bit compression
50
- quantization_config = BitsAndBytesConfig(
51
- load_in_4bit=True,
52
- bnb_4bit_compute_dtype=torch.float16,
53
- bnb_4bit_quant_type="nf4",
54
- bnb_4bit_use_double_quant=True,
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
- pipe = pipeline(
66
- model=model,
67
- tokenizer=tokenizer,
68
- max_new_tokens=256,
69
- temperature= 0.3,
70
- do_sample= True
 
71
  )
72
-
73
- return HuggingFacePipeline(pipeline=pipe)
 
 
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(server_name= '0.0.0.0', server_port= 7860)
 
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()