maxxcarl commited on
Commit
1c6dddf
·
1 Parent(s): 9ed0273

Upload kaggle_auto.ipynb with huggingface_hub

Browse files
Files changed (1) hide show
  1. kaggle_auto.ipynb +81 -0
kaggle_auto.ipynb ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🎵 Spotify Genre Classifier - Automatic Training
2
+ #
3
+ # Kaggle Notebook: Just run this single cell!
4
+ #
5
+ # Setup:
6
+ # 1. Add secrets in Kaggle: HF_TOKEN and HF_USERNAME
7
+ # 2. Run this cell
8
+ # 3. Wait for training to complete (~15-20 min on GPU)
9
+ # 4. Model will be saved and optionally pushed to HF Hub
10
+
11
+ print("=" * 60)
12
+ print(" Spotify Genre Classifier - Automatic Training")
13
+ print("=" * 60)
14
+
15
+ # Step 1: Get secrets
16
+ from kaggle_secrets import UserSecretsClient
17
+ import os
18
+
19
+ user_secrets = UserSecretsClient()
20
+ os.environ['HF_TOKEN'] = user_secrets.get_secret("HF_TOKEN")
21
+ os.environ['HF_USERNAME'] = user_secrets.get_secret("HF_USERNAME")
22
+
23
+ print(f"\n✓ Logged in as: {os.environ['HF_USERNAME']}")
24
+
25
+ # Step 2: Install dependencies
26
+ print("\n📦 Installing dependencies...")
27
+ !pip install -q transformers datasets accelerate evaluate scikit-learn python-dotenv tqdm
28
+
29
+ # Step 3: Clone repo
30
+ print("\n📥 Cloning training repo...")
31
+ !git clone https://huggingface.co/maxxcarl/spotify-training
32
+ %cd spotify-training
33
+
34
+ # Step 4: Check GPU
35
+ print("\n🔍 Checking GPU...")
36
+ import torch
37
+ if torch.cuda.is_available():
38
+ print(f"✓ GPU: {torch.cuda.get_device_name(0)}")
39
+ else:
40
+ print("⚠ No GPU - using CPU")
41
+
42
+ # Step 5: Run training
43
+ print("\n" + "=" * 60)
44
+ print(" Starting Training")
45
+ print("=" * 60)
46
+
47
+ !python src/training_pipeline.py gpt2_spotify
48
+
49
+ # Step 6: Test model
50
+ print("\n" + "=" * 60)
51
+ print(" Testing Model")
52
+ print("=" * 60)
53
+
54
+ !python test_model.py outputs/final_model
55
+
56
+ # Step 7: Push to Hub (optional)
57
+ print("\n" + "=" * 60)
58
+ print(" Push to Hugging Face Hub?")
59
+ print("=" * 60)
60
+
61
+ from huggingface_hub import login
62
+
63
+ hf_token = os.environ['HF_TOKEN']
64
+ username = os.environ['HF_USERNAME']
65
+
66
+ login(token=hf_token)
67
+
68
+ repo_name = "spotify-genre-classifier"
69
+ print(f"\nPushing to: {username}/{repo_name}")
70
+
71
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
72
+
73
+ model = AutoModelForSequenceClassification.from_pretrained("./outputs/final_model")
74
+ tokenizer = AutoTokenizer.from_pretrained("./outputs/final_model")
75
+
76
+ model.push_to_hub(f"{username}/{repo_name}")
77
+ tokenizer.push_to_hub(f"{username}/{repo_name}")
78
+
79
+ print(f"\n✅ Complete!")
80
+ print(f"📊 Model: https://huggingface.co/{username}/{repo_name}")
81
+ print(f"🌐 Space: https://huggingface.co/spaces/{username}/pool")