FlameF0X commited on
Commit
9f30647
ยท
verified ยท
1 Parent(s): 32c80ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -62,11 +62,18 @@ def train_thread_target(
62
  Background thread for training.
63
  """
64
  try:
65
- username = get_user_info(token)
 
 
 
 
 
66
  if not username:
67
- raise ValueError("Invalid Hugging Face Token. Could not authenticate.")
68
 
69
- full_repo_id = f"{username}/{model_name}"
 
 
70
  log_queue.put(f"๐Ÿš€ Initializing for {full_repo_id}...\n")
71
 
72
  # 1. Load Dataset
@@ -145,8 +152,8 @@ def train_thread_target(
145
 
146
  # 5. Push to Hub
147
  log_queue.put(f"โ˜๏ธ Pushing weights to https://huggingface.co/{full_repo_id}...\n")
148
- model.push_to_hub(full_repo_id, token=token)
149
- tokenizer.push_to_hub(full_repo_id, token=token)
150
 
151
  result_queue.put(f"๐ŸŽ‰ Success! Model published to: https://huggingface.co/{full_repo_id}")
152
 
@@ -162,15 +169,18 @@ def train_and_push_generator(
162
  epochs, lr, weight_decay, warmup_steps,
163
  batch_size, grad_accumulation, sample_limit
164
  ):
165
- if not token:
166
- yield "Error: Hugging Face Token is required.", ""
 
 
 
167
  return
168
 
169
  log_queue = queue.Queue()
170
  result_queue = queue.Queue()
171
 
172
  t = threading.Thread(target=train_thread_target, args=(
173
- token, dataset_id, model_name,
174
  num_layers, n_embd, n_head, context_length,
175
  epochs, lr, weight_decay, warmup_steps,
176
  batch_size, grad_accumulation, sample_limit,
@@ -198,14 +208,14 @@ def train_and_push_generator(
198
 
199
  with gr.Blocks(theme=gr.themes.Default(primary_hue="orange", secondary_hue="gray")) as demo:
200
  gr.Markdown("# ๐Ÿ”ฅ Advanced Auto-PreTrain")
201
- gr.Markdown("Configure your transformer architecture and train it directly to your Hugging Face account.")
202
 
203
  with gr.Row():
204
  hf_token = gr.Textbox(
205
- label="Hugging Face Write Token",
206
  placeholder="hf_...",
207
  type="password",
208
- info="Get your token at huggingface.co/settings/tokens (must have 'Write' access)"
209
  )
210
  model_name_input = gr.Textbox(
211
  label="Model Repository Name",
 
62
  Background thread for training.
63
  """
64
  try:
65
+ # Check if the token is provided or should be pulled from Environment Secrets
66
+ final_token = token
67
+ if not final_token:
68
+ final_token = os.environ.get("HF_TOKEN")
69
+
70
+ username = get_user_info(final_token)
71
  if not username:
72
+ raise ValueError("Invalid Hugging Face Token. Please provide a token in the UI or set HF_TOKEN in your environment secrets.")
73
 
74
+ # Updated to push specifically to the Auto-PreTrain organization
75
+ org_name = "Auto-PreTrain"
76
+ full_repo_id = f"{org_name}/{model_name}"
77
  log_queue.put(f"๐Ÿš€ Initializing for {full_repo_id}...\n")
78
 
79
  # 1. Load Dataset
 
152
 
153
  # 5. Push to Hub
154
  log_queue.put(f"โ˜๏ธ Pushing weights to https://huggingface.co/{full_repo_id}...\n")
155
+ model.push_to_hub(full_repo_id, token=final_token)
156
+ tokenizer.push_to_hub(full_repo_id, token=final_token)
157
 
158
  result_queue.put(f"๐ŸŽ‰ Success! Model published to: https://huggingface.co/{full_repo_id}")
159
 
 
169
  epochs, lr, weight_decay, warmup_steps,
170
  batch_size, grad_accumulation, sample_limit
171
  ):
172
+ # If UI token is empty, we attempt to use the environment variable secret
173
+ effective_token = token or os.environ.get("HF_TOKEN")
174
+
175
+ if not effective_token:
176
+ yield "Error: No Hugging Face Token found. Either enter it below or set HF_TOKEN in Secrets.", ""
177
  return
178
 
179
  log_queue = queue.Queue()
180
  result_queue = queue.Queue()
181
 
182
  t = threading.Thread(target=train_thread_target, args=(
183
+ effective_token, dataset_id, model_name,
184
  num_layers, n_embd, n_head, context_length,
185
  epochs, lr, weight_decay, warmup_steps,
186
  batch_size, grad_accumulation, sample_limit,
 
208
 
209
  with gr.Blocks(theme=gr.themes.Default(primary_hue="orange", secondary_hue="gray")) as demo:
210
  gr.Markdown("# ๐Ÿ”ฅ Advanced Auto-PreTrain")
211
+ gr.Markdown("Configure your transformer architecture and train it directly to the **Auto-PreTrain** organization.")
212
 
213
  with gr.Row():
214
  hf_token = gr.Textbox(
215
+ label="Hugging Face Write Token (Optional if set in Secrets)",
216
  placeholder="hf_...",
217
  type="password",
218
+ info="Leave blank if you have 'HF_TOKEN' set in your environment/secrets. Token must have write access to 'Auto-PreTrain' org."
219
  )
220
  model_name_input = gr.Textbox(
221
  label="Model Repository Name",