File size: 5,356 Bytes
3c06493
37d5f61
 
 
 
3c06493
 
37d5f61
3c06493
 
 
 
 
37d5f61
 
9543568
37d5f61
9543568
37d5f61
9543568
 
 
 
37d5f61
9543568
37d5f61
9543568
37d5f61
9543568
 
37d5f61
 
9543568
37d5f61
9543568
37d5f61
 
 
9543568
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37d5f61
 
9543568
37d5f61
 
 
 
9543568
37d5f61
 
 
 
 
 
 
9543568
 
 
 
 
37d5f61
9543568
 
 
 
37d5f61
9543568
37d5f61
9543568
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37d5f61
9543568
37d5f61
9543568
 
 
 
 
 
 
 
 
 
37d5f61
 
 
 
 
 
 
 
 
 
 
 
 
9543568
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
title: AI Phone Leaderboard
emoji: πŸ“±
colorFrom: blue
colorTo: purple
sdk: streamlit
sdk_version: 1.41.0
app_file: main.py
pinned: false
license: mit
short_description: AI Phone Leaderboard
---

# AI Phone Benchmark Leaderboard

A Streamlit dashboard for displaying and analyzing mobile device AI benchmark results. The dashboard fetches data from Firebase Firestore and provides interactive visualizations and filtering capabilities.

## Setup

### Prerequisites
- Python 3.10+
- Firebase project with Firestore database
- Hugging Face account (for deployment)

### Local Development

1. Clone the repository:
```bash
git clone https://github.com/yourusername/ai-phone-leaderboard.git
cd ai-phone-leaderboard
```

2. Create a virtual environment and install dependencies:
```bash
make venv
make setup-dev
```

### Firebase Configuration

1. Create a Firebase Service Account:
   - Go to Firebase Console β†’ Project Settings β†’ Service Accounts
   - Create a new service account for the dashboard:
     ```bash
     # Create service account
     gcloud iam service-accounts create dashboard-firestore-reader \
         --description="Service account for reading Firestore data in the dashboard" \
         --display-name="Dashboard Firestore Reader"
     ```
   - Grant minimal required permissions:
     ```bash
     # Grant Firestore read-only access
     gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \
         --member="serviceAccount:dashboard-firestore-reader@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
         --role="roles/datastore.viewer"
     ```
   - Generate and download the service account key:
     - Click "Generate New Private Key"
     - Save the JSON file (don't commit this to git)

2. For local development, create `.streamlit/secrets.toml`:
```toml
FIREBASE_CREDENTIALS = '''
{
  "type": "service_account",
  "project_id": "your-project-id",
  "private_key_id": "your-private-key-id",
  "private_key": "your-private-key",
  "client_email": "your-client-email",
  "client_id": "your-client-id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "your-client-cert-url",
  "universe_domain": "googleapis.com"
}
'''
```

3. Run the application:
```bash
make run
```

## Deployment to Hugging Face Spaces

1. Create a new Space:
   - Go to huggingface.co/spaces
   - Click "Create new Space"
   - Select "Streamlit" as the SDK
   - Choose a name for your space

2. Add Firebase credentials to Spaces:
   - Go to Space Settings β†’ Repository Secrets
   - Add a new secret named `FIREBASE_CREDENTIALS`
   - Value should be your Firebase credentials as a minified JSON string (single line)
   - Note: Convert the private key's newlines to `\n` in the JSON

Example of minified credentials for HF Spaces:
```json
{"type":"service_account","project_id":"your-project-id","private_key_id":"your-key-id","private_key":"-----BEGIN PRIVATE KEY-----\\nYour\\nPrivate\\nKey\\nHere\\n-----END PRIVATE KEY-----\\n","client_email":"your-email","client_id":"your-client-id","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"your-cert-url","universe_domain":"googleapis.com"}
```

3. The application will automatically deploy when you push to the repository.

## Project Structure
```
.
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .streamlit/
β”‚   └── secrets.toml
β”œβ”€β”€ requirements/
β”‚   β”œβ”€β”€ base.txt
β”‚   β”œβ”€β”€ dev.txt
β”‚   └── prod.txt
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ filters.py
β”‚   β”‚   β”œβ”€β”€ header.py
β”‚   β”‚   └── visualizations.py
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   └── config.py
β”‚   └── services/
β”‚       └── firebase.py
β”œβ”€β”€ main.py
└── requirements.txt
```

## Firebase Data Structure

The application expects the following Firestore collection structure:
```
benchmarks/
└── v1/
    └── submissions/
        └── [benchmark_uuid]/
            β”œβ”€β”€ benchmarkResult: {...}
            β”œβ”€β”€ deviceInfo: {...}
            └── metadata: {...}
```

## Development

Available make commands:
```bash
make help           # Show available commands
make setup-dev      # Setup development environment
make setup-prod     # Setup production environment
make run           # Run Streamlit application
make lint          # Run code linter
make format        # Format code using black
make test          # Run tests
make clean         # Clean cache files
```

## Security Considerations

1. Never commit sensitive credentials to git:
```gitignore
# Add to .gitignore
.streamlit/secrets.toml
*firebase*.json
```

2. Use environment-specific secrets:
   - Local: Use `.streamlit/secrets.toml`
   - Production: Use HF Spaces secrets

3. Firebase Security:
   - Create a dedicated service account with minimal permissions
   - Only grant read access to the required Firestore collections

## Dependencies

Key dependencies are pinned to specific versions to ensure stability:
```
firebase-admin==6.6.0
streamlit>=1.28.0
pandas>=2.1.3
plotly>=5.18.0
```

## License

[MIT License](LICENSE)