Or4cl3-2 commited on
Commit
de09b5f
·
verified ·
1 Parent(s): 84af71c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -5
app.py CHANGED
@@ -469,11 +469,25 @@ class ArchitechAgent:
469
 
470
  try:
471
  login(token=hf_token)
472
- model.push_to_hub(model_name, token=hf_token)
473
- tokenizer.push_to_hub(model_name, token=hf_token)
474
- hub_url = f"https://huggingface.co/{username}/{model_name}"
475
 
476
- return f"""🎉 **TRAINING COMPLETE!**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
  ✅ Training successful
479
  💾 Model saved locally
@@ -486,9 +500,47 @@ class ArchitechAgent:
486
  - Learning rate: {learning_rate}
487
 
488
  **Test it in the 'Test Model' tab!**"""
 
 
 
 
 
 
 
 
489
 
490
  except Exception as e:
491
- return f" Training done but upload failed: {str(e)}\nModel saved at: {output_dir}"# ==================== GRADIO INTERFACE ====================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
 
493
  def create_gradio_interface():
494
  agent = ArchitechAgent()
 
469
 
470
  try:
471
  login(token=hf_token)
 
 
 
472
 
473
+ # Try uploading with retries
474
+ max_retries = 3
475
+ for attempt in range(max_retries):
476
+ try:
477
+ progress(0.9 + (attempt * 0.03), f"📤 Upload attempt {attempt + 1}/{max_retries}...")
478
+
479
+ # Push model with timeout
480
+ model.push_to_hub(
481
+ model_name,
482
+ token=hf_token,
483
+ max_shard_size="500MB",
484
+ safe_serialization=True
485
+ )
486
+ tokenizer.push_to_hub(model_name, token=hf_token)
487
+
488
+ hub_url = f"https://huggingface.co/{username}/{model_name}"
489
+
490
+ return f"""🎉 **TRAINING COMPLETE!**
491
 
492
  ✅ Training successful
493
  💾 Model saved locally
 
500
  - Learning rate: {learning_rate}
501
 
502
  **Test it in the 'Test Model' tab!**"""
503
+
504
+ except Exception as upload_error:
505
+ if attempt < max_retries - 1:
506
+ logger.warning(f"Upload attempt {attempt + 1} failed: {upload_error}")
507
+ time.sleep(5) # Wait before retry
508
+ continue
509
+ else:
510
+ raise upload_error
511
 
512
  except Exception as e:
513
+ logger.error(f"Upload failed after retries: {e}")
514
+
515
+ # Provide manual upload instructions
516
+ return f"""✅ **TRAINING COMPLETE!** (Upload timed out)
517
+
518
+ 💾 Model saved locally at: `{output_dir}`
519
+
520
+ **Manual Upload Instructions:**
521
+ 1. Download your Space's files (or access via SSH if enabled)
522
+ 2. Run this command locally:
523
+ ```bash
524
+ huggingface-cli upload {username}/{model_name} {output_dir}
525
+ ```
526
+
527
+ Or use the Python API:
528
+ ```python
529
+ from huggingface_hub import HfApi
530
+ api = HfApi()
531
+ api.upload_folder(
532
+ folder_path="{output_dir}",
533
+ repo_id="{username}/{model_name}",
534
+ token="YOUR_TOKEN"
535
+ )
536
+ ```
537
+
538
+ **Stats:**
539
+ - Examples: {len(texts)}
540
+ - Epochs: {num_epochs}
541
+ - Model saved successfully!
542
+
543
+ **You can still test it locally or manually upload!**"""# ==================== GRADIO INTERFACE ====================
544
 
545
  def create_gradio_interface():
546
  agent = ArchitechAgent()