cheberle commited on
Commit
974dd09
·
1 Parent(s): b7b3996
Files changed (2) hide show
  1. app.py +10 -9
  2. requirements.txt +1 -1
app.py CHANGED
@@ -5,12 +5,12 @@ from transformers import AutoTokenizer, TrainingArguments, Trainer, AutoModelFor
5
  import torch
6
  import os
7
 
8
- # Force CPU
9
  os.environ["CUDA_VISIBLE_DEVICES"] = ""
10
 
11
  def train_model(file, hf_token):
12
  try:
13
- # Basic data loading test
14
  df = pd.read_csv(file.name)
15
  print(f"Loaded CSV with {len(df)} rows")
16
 
@@ -20,19 +20,19 @@ def train_model(file, hf_token):
20
  model = AutoModelForCausalLM.from_pretrained(
21
  model_name,
22
  low_cpu_mem_usage=True,
23
- torch_dtype=torch.float32
24
  )
25
 
26
- # Basic dataset creation
27
  dataset = Dataset.from_pandas(df)
28
 
29
  args = TrainingArguments(
30
  output_dir="./results",
31
  per_device_train_batch_size=1,
32
  num_train_epochs=1,
33
- no_cuda=True,
34
- local_rank=-1,
35
- use_cpu=True
36
  )
37
 
38
  trainer = Trainer(
@@ -42,11 +42,12 @@ def train_model(file, hf_token):
42
  tokenizer=tokenizer
43
  )
44
 
45
- return f"Setup successful! Loaded {len(df)} rows"
46
 
47
  except Exception as e:
48
  return f"Error: {str(e)}\nType: {type(e)}"
49
 
 
50
  demo = gr.Interface(
51
  fn=train_model,
52
  inputs=[
@@ -58,4 +59,4 @@ demo = gr.Interface(
58
  )
59
 
60
  if __name__ == "__main__":
61
- demo.launch(debug=True)
 
5
  import torch
6
  import os
7
 
8
+ # Force CPU-only execution
9
  os.environ["CUDA_VISIBLE_DEVICES"] = ""
10
 
11
  def train_model(file, hf_token):
12
  try:
13
+ # Basic data loading
14
  df = pd.read_csv(file.name)
15
  print(f"Loaded CSV with {len(df)} rows")
16
 
 
20
  model = AutoModelForCausalLM.from_pretrained(
21
  model_name,
22
  low_cpu_mem_usage=True,
23
+ torch_dtype=torch.float32 # Ensure compatibility with CPU
24
  )
25
 
26
+ # Prepare dataset
27
  dataset = Dataset.from_pandas(df)
28
 
29
  args = TrainingArguments(
30
  output_dir="./results",
31
  per_device_train_batch_size=1,
32
  num_train_epochs=1,
33
+ no_cuda=True, # Disable GPU
34
+ use_cpu=True, # Ensure CPU usage
35
+ fp16=False # Disable mixed precision
36
  )
37
 
38
  trainer = Trainer(
 
42
  tokenizer=tokenizer
43
  )
44
 
45
+ return f"Setup successful! Loaded {len(df)} rows for training."
46
 
47
  except Exception as e:
48
  return f"Error: {str(e)}\nType: {type(e)}"
49
 
50
+ # Gradio interface
51
  demo = gr.Interface(
52
  fn=train_model,
53
  inputs=[
 
59
  )
60
 
61
  if __name__ == "__main__":
62
+ demo.launch(debug=True, ssr=False) # Disable SSR for compatibility
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==4.19.2
2
  transformers==4.37.2
3
  torch==2.1.2
4
  datasets==2.16.1
 
1
+ gradio==5.12.0
2
  transformers==4.37.2
3
  torch==2.1.2
4
  datasets==2.16.1