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

Upload kaggle_single_cell.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. kaggle_single_cell.py +56 -0
kaggle_single_cell.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Kaggle Auto-Training Notebook
2
+ # Copy this entire file into a single Kaggle notebook cell
3
+
4
+ print("=" * 60)
5
+ print(" Spotify Genre Classifier - Automatic Training")
6
+ print("=" * 60)
7
+
8
+ # Get secrets
9
+ from kaggle_secrets import UserSecretsClient
10
+ import os
11
+
12
+ user_secrets = UserSecretsClient()
13
+ os.environ['HF_TOKEN'] = user_secrets.get_secret("HF_TOKEN")
14
+ os.environ['HF_USERNAME'] = user_secrets.get_secret("HF_USERNAME")
15
+
16
+ print(f"\n✓ Logged in as: {os.environ['HF_USERNAME']}")
17
+
18
+ # Install
19
+ print("\n📦 Installing...")
20
+ !pip install -q transformers datasets accelerate evaluate scikit-learn python-dotenv tqdm
21
+
22
+ # Clone
23
+ print("\n📥 Cloning...")
24
+ !git clone https://huggingface.co/maxxcarl/spotify-training
25
+ %cd spotify-training
26
+
27
+ # Check GPU
28
+ print("\n🔍 GPU:")
29
+ import torch
30
+ if torch.cuda.is_available():
31
+ print(f"✓ {torch.cuda.get_device_name(0)}")
32
+ else:
33
+ print("⚠ CPU only")
34
+
35
+ # Train
36
+ print("\n🚀 Training...")
37
+ !python src/training_pipeline.py gpt2_spotify
38
+
39
+ # Test
40
+ print("\n📈 Testing...")
41
+ !python test_model.py outputs/final_model
42
+
43
+ # Push to Hub
44
+ print("\n💾 Pushing to Hub...")
45
+ from huggingface_hub import login
46
+ login(token=os.environ['HF_TOKEN'])
47
+
48
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
49
+ model = AutoModelForSequenceClassification.from_pretrained("./outputs/final_model")
50
+ tokenizer = AutoTokenizer.from_pretrained("./outputs/final_model")
51
+
52
+ username = os.environ['HF_USERNAME']
53
+ model.push_to_hub(f"{username}/spotify-genre-classifier")
54
+ tokenizer.push_to_hub(f"{username}/spotify-genre-classifier")
55
+
56
+ print(f"\n✅ Done! https://huggingface.co/{username}/spotify-genre-classifier")