Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,11 +62,18 @@ def train_thread_target(
|
|
| 62 |
Background thread for training.
|
| 63 |
"""
|
| 64 |
try:
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
if not username:
|
| 67 |
-
raise ValueError("Invalid Hugging Face Token.
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
| 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=
|
| 149 |
-
tokenizer.push_to_hub(full_repo_id, 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 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
| 167 |
return
|
| 168 |
|
| 169 |
log_queue = queue.Queue()
|
| 170 |
result_queue = queue.Queue()
|
| 171 |
|
| 172 |
t = threading.Thread(target=train_thread_target, args=(
|
| 173 |
-
|
| 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
|
| 202 |
|
| 203 |
with gr.Row():
|
| 204 |
hf_token = gr.Textbox(
|
| 205 |
-
label="Hugging Face Write Token",
|
| 206 |
placeholder="hf_...",
|
| 207 |
type="password",
|
| 208 |
-
info="
|
| 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",
|