WillemVH commited on
Commit
cf72181
·
verified ·
1 Parent(s): edf04a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -257,15 +257,14 @@ class AITrainerApp:
257
  total_texts = []
258
  for file_info in files:
259
  try:
260
- file_path = file_info.name
261
- with open(file_path, 'r', encoding='utf-8') as f:
262
- content = f.read()
263
- # Split into smaller chunks if needed
264
- chunks = self.split_into_chunks(content, 1000)
265
- total_texts.extend(chunks)
266
- self.output_log = self.log_output(f"Loaded {len(chunks)} chunks from {os.path.basename(file_path)}")
267
  except Exception as e:
268
- error_msg = f"Error reading {file_path}: {str(e)}"
269
  self.output_log = self.log_output(error_msg)
270
  return error_msg, self.output_log
271
 
@@ -300,8 +299,9 @@ class AITrainerApp:
300
 
301
  def start_training(self, d_model, n_layers, n_heads, batch_size, learning_rate, epochs, device_type):
302
  if not self.training_data:
303
- self.output_log = self.log_output("Error: No training data loaded!")
304
- return "Error: No training data loaded!", self.output_log, gr.update(interactive=False)
 
305
 
306
  self.stop_training_flag = False
307
  self.training_status = "Training started..."
 
257
  total_texts = []
258
  for file_info in files:
259
  try:
260
+ # Read the content from the file object
261
+ content = file_info.read().decode('utf-8')
262
+ # Split into smaller chunks if needed
263
+ chunks = self.split_into_chunks(content, 1000)
264
+ total_texts.extend(chunks)
265
+ self.output_log = self.log_output(f"Loaded {len(chunks)} chunks from {file_info.name}")
 
266
  except Exception as e:
267
+ error_msg = f"Error reading {file_info.name}: {str(e)}"
268
  self.output_log = self.log_output(error_msg)
269
  return error_msg, self.output_log
270
 
 
299
 
300
  def start_training(self, d_model, n_layers, n_heads, batch_size, learning_rate, epochs, device_type):
301
  if not self.training_data:
302
+ error_msg = "Error: No training data loaded!"
303
+ self.output_log = self.log_output(error_msg)
304
+ return error_msg, self.output_log, gr.update(interactive=True)
305
 
306
  self.stop_training_flag = False
307
  self.training_status = "Training started..."