acecalisto3 commited on
Commit
e98b8b3
·
verified ·
1 Parent(s): 972bb7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -1164,27 +1164,30 @@ def display_historical_data(storage_location: str, url: str):
1164
  logging.error(f"Error fetching historical data for {url}: {e}")
1165
  return pd.DataFrame()
1166
 
1167
- # Function to load the "google/flan-t5-xl" model
1168
- def load_model():
1169
  """
1170
  Loads the openLlama model and tokenizer once and returns the pipeline.
1171
  """
1172
  try:
1173
- model_name = "openlm-research/open_llama_3b_v2" # Correct indentation here
1174
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False, legacy=False)
1175
- model = AutoModelForCausalLM.from_pretrained(model_name)
1176
 
1177
- # Determine the maximum supported length for the model
1178
- max_supported_length = 2048 # You might need to adjust this
1179
 
1180
- openllama_pipeline = pipeline(
1181
- "text-generation",
 
 
 
 
1182
  temperature=0.7,
1183
  top_p=0.95,
1184
  device=0 if torch.cuda.is_available() else -1,
1185
  )
1186
  logging.info("Model loaded successfully.")
1187
- return pipe
1188
  except Exception as e:
1189
  logging.error(f"Error loading google/flan-t5-xl model: {e}")
1190
  return None
 
1164
  logging.error(f"Error fetching historical data for {url}: {e}")
1165
  return pd.DataFrame()
1166
 
1167
+ def load_model():
 
1168
  """
1169
  Loads the openLlama model and tokenizer once and returns the pipeline.
1170
  """
1171
  try:
1172
+ model_name = "openlm-research/open_llama_3b_v2"
1173
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False, legacy=False)
1174
+ model = AutoModelForCausalLM.from_pretrained(model_name)
1175
 
1176
+ # This should be inside the try block
1177
+ max_supported_length = 2048
1178
 
1179
+ openllama_pipeline = pipeline(
1180
+ "text-generation",
1181
+ model=model,
1182
+ tokenizer=tokenizer,
1183
+ truncation=True,
1184
+ max_length=max_supported_length,
1185
  temperature=0.7,
1186
  top_p=0.95,
1187
  device=0 if torch.cuda.is_available() else -1,
1188
  )
1189
  logging.info("Model loaded successfully.")
1190
+ return openllama_pipeline # Return the pipeline
1191
  except Exception as e:
1192
  logging.error(f"Error loading google/flan-t5-xl model: {e}")
1193
  return None