roshnn24 commited on
Commit
3037245
·
verified ·
1 Parent(s): add1791

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -141,24 +141,33 @@ def init_db():
141
  conn.commit()
142
 
143
  def initialize_llm():
144
- """Initialize the model in the simplest way possible"""
145
  try:
146
  # Get API token
147
  api_token = os.environ.get('HF_TOKEN')
148
  if not api_token:
149
- raise ValueError("No API token found")
150
 
151
- # Initialize with minimal settings
152
- llm = HuggingFaceHub(
153
- repo_id="meta-llama/Llama-3.1-8B-Instruct", # Using a simpler model for testing
154
- huggingfacehub_api_token=api_token,
155
- )
 
 
 
 
 
 
 
 
 
 
 
156
 
157
- # Quick test
158
- test = llm("Say hello")
159
- print(f"Test response: {test}")
160
 
161
- return llm
162
 
163
  except Exception as e:
164
  print(f"LLM initialization error: {str(e)}")
 
141
  conn.commit()
142
 
143
  def initialize_llm():
144
+ """Initialize the LLM using the transformers library."""
145
  try:
146
  # Get API token
147
  api_token = os.environ.get('HF_TOKEN')
148
  if not api_token:
149
+ raise ValueError("No Hugging Face API token found in environment variables.")
150
 
151
+ # Define model repository ID
152
+ model_name = "mistralai/Mistral-7B-Instruct-v0.3"
153
+
154
+ # Load tokenizer and model
155
+ print("Loading tokenizer...")
156
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=api_token)
157
+
158
+ print("Loading model...")
159
+ model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=api_token)
160
+
161
+ # Test the model with a simple prompt
162
+ print("Testing the model...")
163
+ prompt = "Say hello"
164
+ inputs = tokenizer(prompt, return_tensors="pt")
165
+ outputs = model.generate(**inputs, max_length=50)
166
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
167
 
168
+ print(f"Test response: {response}")
 
 
169
 
170
+ return model, tokenizer
171
 
172
  except Exception as e:
173
  print(f"LLM initialization error: {str(e)}")