Spaces:
Running
Running
File size: 5,381 Bytes
ebe598e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
#!/usr/bin/env python3
"""
Configuration script for Trackio environment variables
"""
import os
import json
from datetime import datetime
def configure_trackio():
"""Configure Trackio environment variables"""
print("π§ Trackio Configuration")
print("=" * 40)
# Current configuration
current_config = {
'HF_TOKEN': os.environ.get('HF_TOKEN', 'Not set'),
'TRACKIO_DATASET_REPO': os.environ.get('TRACKIO_DATASET_REPO', 'tonic/trackio-experiments'),
'SPACE_ID': os.environ.get('SPACE_ID', 'Not set')
}
print("π Current Configuration:")
for key, value in current_config.items():
status = "β
" if value != "Not set" else "β"
print(f" {status} {key}: {value}")
print("\nπ― Configuration Options:")
print("1. Set HF_TOKEN - Required for dataset access")
print("2. Set TRACKIO_DATASET_REPO - Dataset repository (optional)")
print("3. Set SPACE_ID - HF Space ID (auto-detected)")
# Check if running on HF Spaces
if os.environ.get('SPACE_ID'):
print("\nπ Running on Hugging Face Spaces")
print(f" Space ID: {os.environ.get('SPACE_ID')}")
# Validate configuration
print("\nπ Configuration Validation:")
# Check HF_TOKEN
if current_config['HF_TOKEN'] != 'Not set':
print("β
HF_TOKEN is set")
print(" This allows the app to read/write to HF Datasets")
else:
print("β HF_TOKEN is not set")
print(" Please set HF_TOKEN to enable dataset functionality")
print(" Get your token from: https://huggingface.co/settings/tokens")
# Check dataset repository
dataset_repo = current_config['TRACKIO_DATASET_REPO']
print(f"π Dataset Repository: {dataset_repo}")
# Test dataset access if token is available
if current_config['HF_TOKEN'] != 'Not set':
print("\nπ§ͺ Testing Dataset Access...")
try:
from datasets import load_dataset
dataset = load_dataset(dataset_repo, token=current_config['HF_TOKEN'])
print(f"β
Successfully loaded dataset: {dataset_repo}")
# Show experiment count
if 'train' in dataset:
experiment_count = len(dataset['train'])
print(f"π Found {experiment_count} experiments in dataset")
# Show sample experiments
if experiment_count > 0:
print("π¬ Sample experiments:")
for i, row in enumerate(dataset['train'][:3]): # Show first 3
exp_id = row.get('experiment_id', 'Unknown')
name = row.get('name', 'Unnamed')
print(f" {i+1}. {exp_id}: {name}")
except Exception as e:
print(f"β Failed to load dataset: {e}")
print(" This might be normal if the dataset doesn't exist yet")
# Generate configuration file
config_file = "trackio_config.json"
config_data = {
'hf_token': current_config['HF_TOKEN'],
'dataset_repo': current_config['TRACKIO_DATASET_REPO'],
'space_id': current_config['SPACE_ID'],
'last_updated': datetime.now().isoformat(),
'notes': 'Trackio configuration - set these as environment variables in your HF Space'
}
with open(config_file, 'w') as f:
json.dump(config_data, f, indent=2)
print(f"\nπΎ Configuration saved to: {config_file}")
# Show environment variable commands
print("\nπ Environment Variables for HF Space:")
print("=" * 50)
print(f"HF_TOKEN={current_config['HF_TOKEN']}")
print(f"TRACKIO_DATASET_REPO={current_config['TRACKIO_DATASET_REPO']}")
print("\nπ― Next Steps:")
print("1. Set HF_TOKEN in your HF Space environment variables")
print("2. Optionally set TRACKIO_DATASET_REPO to use a different dataset")
print("3. Deploy your updated app.py to the Space")
print("4. Run setup_hf_dataset.py if you haven't created the dataset yet")
def show_usage_examples():
"""Show usage examples for different dataset repositories"""
print("\nπ Usage Examples")
print("=" * 30)
examples = [
{
'name': 'Default Dataset',
'repo': 'tonic/trackio-experiments',
'description': 'Default dataset for your experiments'
},
{
'name': 'Personal Dataset',
'repo': 'your-username/trackio-experiments',
'description': 'Your personal experiment dataset'
},
{
'name': 'Team Dataset',
'repo': 'your-org/team-experiments',
'description': 'Shared dataset for team experiments'
},
{
'name': 'Project Dataset',
'repo': 'your-username/smollm3-experiments',
'description': 'Dataset specific to SmolLM3 experiments'
}
]
for i, example in enumerate(examples, 1):
print(f"{i}. {example['name']}")
print(f" Repository: {example['repo']}")
print(f" Description: {example['description']}")
print(f" Set with: TRACKIO_DATASET_REPO={example['repo']}")
print()
if __name__ == "__main__":
configure_trackio()
show_usage_examples() |