Tachyon99 commited on
Commit
8e487f2
·
verified ·
1 Parent(s): 0b11374

Update model_utils.py

Browse files
Files changed (1) hide show
  1. model_utils.py +18 -29
model_utils.py CHANGED
@@ -4,9 +4,8 @@ import pandas as pd
4
  import numpy as np
5
  import plotly.graph_objects as go
6
  from scipy.ndimage import gaussian_filter1d
7
- from llama_cpp import Llama
8
- from huggingface_hub import hf_hub_download
9
-
10
  # (The code at the top of the file remains exactly the same)
11
  # ...
12
  # --- 1. Define Categories and Features ---
@@ -50,25 +49,13 @@ def load_lgbm_model():
50
  return None
51
 
52
  def load_llm_model():
53
- # Change to your Hugging Face repo and filename
54
- repo_id = "bartowski/Llama-3.2-1B-Instruct-GGUF"
55
- filename = "Llama-3.2-1B-Instruct-Q5_K_S.gguf"
56
-
57
  try:
58
- print("Downloading Llama 3 GGUF model from Hugging Face...")
59
- model_path = hf_hub_download(repo_id=repo_id, filename=filename)
60
-
61
- print("Loading Llama 3 GGUF model...")
62
- llm = Llama(
63
- model_path=model_path,
64
- chat_format="llama-3",
65
- n_gpu_layers=0,
66
- n_ctx=512,
67
- verbose=False
68
- )
69
  print("Llama 3 model loaded successfully.")
70
  return llm
71
-
72
  except Exception as e:
73
  print(f"---!!! LLM LOAD ERROR !!!---: {e}")
74
  return None
@@ -193,15 +180,17 @@ def prediction_pipeline(lgbm_model, parent_cat, sub_cat, country, currency, mont
193
  return probability_html, goal_fig, month_fig, subcat_fig
194
 
195
  def generate_blurb_pipeline(llm, parent_cat, sub_cat, user_prompt):
196
- if llm is None: return "LLM not loaded. Please check logs."
197
- if not all([parent_cat, sub_cat, user_prompt]): return "Please select a category, sub-category, and describe your company first."
198
- messages = [
199
- {"role": "system", "content": f"You are a helpful and friendly assistant who provides concise, and catchy blurbs. The product category is {parent_cat} and the sub-category is {sub_cat}."},
200
- {"role": "user", "content": user_prompt}
201
- ]
 
 
202
  try:
203
- response = llm.create_chat_completion(messages=messages, max_tokens=512, temperature=0.7, stop=["<|eot_id|>"])
204
- assistant_message = response['choices'][0]['message']['content']
205
- return assistant_message.strip()
206
  except Exception as e:
207
- return f"An error occurred during blurb generation: {e}"
 
4
  import numpy as np
5
  import plotly.graph_objects as go
6
  from scipy.ndimage import gaussian_filter1d
7
+ from gpt4all import GPT4All
8
+ import os
 
9
  # (The code at the top of the file remains exactly the same)
10
  # ...
11
  # --- 1. Define Categories and Features ---
 
49
  return None
50
 
51
  def load_llm_model():
52
+ # Absolute path to the GGUF model file
53
+ model_path = os.path.abspath("models/Llama-3.2-1B-Instruct-Q5_K_S.gguf")
 
 
54
  try:
55
+ print("Loading Llama 3 GGUF model (gpt4all, CPU mode)...")
56
+ llm = GPT4All(model_path) # full path to your file
 
 
 
 
 
 
 
 
 
57
  print("Llama 3 model loaded successfully.")
58
  return llm
 
59
  except Exception as e:
60
  print(f"---!!! LLM LOAD ERROR !!!---: {e}")
61
  return None
 
180
  return probability_html, goal_fig, month_fig, subcat_fig
181
 
182
  def generate_blurb_pipeline(llm, parent_cat, sub_cat, user_prompt):
183
+ if llm is None:
184
+ return "LLM not loaded. Please check logs."
185
+ if not all([parent_cat, sub_cat, user_prompt]):
186
+ return "Please select a category, sub-category, and describe your company first."
187
+
188
+ system_message = f"You are a helpful and friendly assistant who provides concise, catchy blurbs. The product category is {parent_cat} and the sub-category is {sub_cat}."
189
+ full_prompt = f"{system_message}\nUser: {user_prompt}\nAssistant:"
190
+
191
  try:
192
+ with llm.chat_session():
193
+ response = llm.generate(full_prompt, max_tokens=512, temp=0.7)
194
+ return response.strip()
195
  except Exception as e:
196
+ return f"An error occurred during blurb generation: {e}"