sudzdpn commited on
Commit
ac58df0
·
verified ·
1 Parent(s): 9008ef5

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +29 -11
  2. index.html +85 -19
  3. script.js +201 -0
  4. styles.css +249 -0
README.md CHANGED
@@ -1,11 +1,29 @@
1
- ---
2
- title: Ai Usage Tracker
3
- emoji: 🚀
4
- colorFrom: purple
5
- colorTo: blue
6
- sdk: static
7
- pinned: false
8
- short_description: personal tracker for sudz
9
- ---
10
-
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI Usage Tracker
2
+
3
+ Modern single-page app to track usage of free-tier AI services (Grok, Claude, Gemini, Perplexity, etc.).
4
+
5
+ ## Features
6
+
7
+ - Daily / Weekly / Monthly reset periods
8
+ - Visual progress bars + doughnut charts
9
+ - Service-specific icons
10
+ - Usage logging with purpose/description
11
+ - Export data as JSON
12
+ - 100% client-side (localStorage)
13
+
14
+ ## Deployment
15
+
16
+ ### GitHub Pages
17
+ - Push files to repo
18
+ - Settings → Pages → Source: main branch → root
19
+
20
+ → https://sudz.github.io/ai-usage-tracker/
21
+
22
+ ### Hugging Face Spaces
23
+ - Create Static Space
24
+ - Upload files or connect GitHub repo
25
+
26
+ → https://huggingface.co/spaces/sudzdpn/ai-usage-tracker
27
+
28
+ Enjoy tracking!
29
+ @sudzdpn / @SudzdPN
index.html CHANGED
@@ -1,19 +1,85 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>AI Usage Tracker</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
9
+ <link rel="stylesheet" href="styles.css">
10
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.4/dist/chart.umd.min.js"></script>
11
+ </head>
12
+ <body>
13
+ <nav class="navbar">
14
+ <div class="logo">
15
+ <i class="fas fa-robot"></i> AI Usage Tracker
16
+ </div>
17
+ <div class="nav-links">
18
+ <a href="#dashboard"><i class="fas fa-tachometer-alt"></i> Dashboard</a>
19
+ <a href="#history"><i class="fas fa-history"></i> History</a>
20
+ <a href="#add-service"><i class="fas fa-plus"></i> Add Service</a>
21
+ </div>
22
+ </nav>
23
+
24
+ <div class="container">
25
+ <section id="dashboard">
26
+ <h1 class="section-title">Dashboard</h1>
27
+ <button class="button secondary" onclick="exportData()" style="margin-bottom: 1.5rem;">
28
+ <i class="fas fa-download"></i> Export Data (JSON)
29
+ </button>
30
+ <div id="services-cards" class="cards"></div>
31
+ </section>
32
+
33
+ <section id="history" style="display: none;">
34
+ <h1 class="section-title">Usage History</h1>
35
+ <ul id="history-list"></ul>
36
+ </section>
37
+
38
+ <section id="add-service" style="display: none;">
39
+ <h1 class="section-title">Add New AI Service</h1>
40
+ <form id="add-service-form">
41
+ <div class="form-group">
42
+ <label for="service-name">Service Name</label>
43
+ <input type="text" id="service-name" required placeholder="e.g. Grok, Claude, Gemini, Perplexity">
44
+ </div>
45
+ <div class="form-group">
46
+ <label for="limit">Free Tier Limit</label>
47
+ <input type="number" id="limit" required min="1" placeholder="e.g. 50">
48
+ </div>
49
+ <div class="form-group">
50
+ <label for="refresh-period">Reset / Refresh Period</label>
51
+ <select id="refresh-period" required>
52
+ <option value="daily">Daily</option>
53
+ <option value="weekly">Weekly</option>
54
+ <option value="monthly">Monthly</option>
55
+ </select>
56
+ </div>
57
+ <button type="submit" class="button primary">
58
+ <i class="fas fa-plus"></i> Add Service
59
+ </button>
60
+ </form>
61
+ </section>
62
+ </div>
63
+
64
+ <!-- Log Usage Modal -->
65
+ <div id="log-modal" class="modal">
66
+ <div class="modal-content">
67
+ <span class="close" onclick="closeModal()">&times;</span>
68
+ <h2>Log Usage</h2>
69
+ <form id="log-form">
70
+ <div class="form-group">
71
+ <label for="usage-amount">Amount Used</label>
72
+ <input type="number" id="usage-amount" value="1" min="1" required>
73
+ </div>
74
+ <div class="form-group">
75
+ <label for="usage-description">What did you use it for?</label>
76
+ <input type="text" id="usage-description" required placeholder="e.g. Code generation, research question, image generation">
77
+ </div>
78
+ <button type="submit" class="button primary">Log</button>
79
+ </form>
80
+ </div>
81
+ </div>
82
+
83
+ <script src="script.js"></script>
84
+ </body>
85
+ </html>
script.js ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ let services = JSON.parse(localStorage.getItem('services')) || [];
2
+ let history = JSON.parse(localStorage.getItem('history')) || [];
3
+
4
+ function saveData() {
5
+ localStorage.setItem('services', JSON.stringify(services));
6
+ localStorage.setItem('history', JSON.stringify(history));
7
+ }
8
+
9
+ function calculateRefreshTime(period) {
10
+ const now = new Date();
11
+ let refreshDate = new Date(now);
12
+ refreshDate.setHours(0, 0, 0, 0);
13
+
14
+ if (period === 'daily') {
15
+ refreshDate.setDate(now.getDate() + 1);
16
+ } else if (period === 'weekly') {
17
+ refreshDate.setDate(now.getDate() + 7);
18
+ } else if (period === 'monthly') {
19
+ refreshDate.setMonth(now.getMonth() + 1);
20
+ refreshDate.setDate(1);
21
+ }
22
+
23
+ return refreshDate;
24
+ }
25
+
26
+ function getCurrentUsage(service) {
27
+ const now = new Date();
28
+ const refreshTime = new Date(service.refreshTime);
29
+ if (now >= refreshTime) {
30
+ service.currentUsage = 0;
31
+ service.refreshTime = calculateRefreshTime(service.refreshPeriod).toISOString();
32
+ saveData();
33
+ }
34
+ return service.currentUsage || 0;
35
+ }
36
+
37
+ function getServiceIcon(name) {
38
+ const n = name.toLowerCase();
39
+ if (n.includes('grok') || n.includes('xai')) return 'fa-robot';
40
+ if (n.includes('claude') || n.includes('anthropic')) return 'fa-comment-dots';
41
+ if (n.includes('gemini') || n.includes('google')) return 'fa-google';
42
+ if (n.includes('chatgpt') || n.includes('openai')) return 'fa-comment-medical';
43
+ if (n.includes('perplexity')) return 'fa-search';
44
+ if (n.includes('copilot') || n.includes('github')) return 'fa-github';
45
+ if (n.includes('llama') || n.includes('meta')) return 'fa-meta';
46
+ return 'fa-brain';
47
+ }
48
+
49
+ function renderServices() {
50
+ const container = document.getElementById('services-cards');
51
+ container.innerHTML = '';
52
+
53
+ services.forEach((service, index) => {
54
+ const used = getCurrentUsage(service);
55
+ const remaining = service.limit - used;
56
+ const pct = service.limit > 0 ? (used / service.limit) * 100 : 0;
57
+ const refreshDate = new Date(service.refreshTime);
58
+ const icon = getServiceIcon(service.name);
59
+
60
+ const card = document.createElement('div');
61
+ card.className = 'card';
62
+ card.innerHTML = `
63
+ <h2 class="card-title"><i class="fas ${icon}"></i> ${service.name}</h2>
64
+
65
+ <div class="progress-container">
66
+ <div class="progress-bar">
67
+ <div class="progress-fill" style="width: ${pct}%; background: ${pct < 50 ? '#22c55e' : pct < 80 ? '#eab308' : '#ef4444'}"></div>
68
+ </div>
69
+ <p class="progress-text">${used} / ${service.limit} (${remaining} remaining)</p>
70
+ </div>
71
+
72
+ <div class="chart-container">
73
+ <canvas id="chart-${index}"></canvas>
74
+ </div>
75
+
76
+ <p class="card-info"><i class="fas fa-sync-alt"></i> Refreshes: ${refreshDate.toLocaleString()}</p>
77
+
78
+ <button class="button primary" onclick="openLogModal(${index})">
79
+ <i class="fas fa-plus-circle"></i> Log Usage
80
+ </button>
81
+ `;
82
+ container.appendChild(card);
83
+
84
+ new Chart(document.getElementById(`chart-${index}`), {
85
+ type: 'doughnut',
86
+ data: {
87
+ labels: ['Used', 'Remaining'],
88
+ datasets: [{
89
+ data: [used, remaining],
90
+ backgroundColor: ['#f97316', '#e2e8f0'],
91
+ borderWidth: 0
92
+ }]
93
+ },
94
+ options: {
95
+ responsive: true,
96
+ maintainAspectRatio: false,
97
+ cutout: '70%',
98
+ plugins: { legend: { display: false } }
99
+ }
100
+ });
101
+ });
102
+ }
103
+
104
+ function exportData() {
105
+ const data = {
106
+ services,
107
+ history,
108
+ exportedAt: new Date().toISOString(),
109
+ note: "AI Usage Tracker export – import not yet implemented"
110
+ };
111
+ const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
112
+ const url = URL.createObjectURL(blob);
113
+ const a = document.createElement('a');
114
+ a.href = url;
115
+ a.download = `ai-usage-tracker-${new Date().toISOString().slice(0,10)}.json`;
116
+ a.click();
117
+ URL.revokeObjectURL(url);
118
+ }
119
+
120
+ function renderHistory() {
121
+ const list = document.getElementById('history-list');
122
+ list.innerHTML = '';
123
+ history.forEach(entry => {
124
+ const li = document.createElement('li');
125
+ li.innerHTML = `
126
+ <strong>${entry.service}</strong> — ${entry.amount} used
127
+ <br><small>${new Date(entry.timestamp).toLocaleString()}</small>
128
+ <p>"${entry.description}"</p>
129
+ `;
130
+ list.appendChild(li);
131
+ });
132
+ }
133
+
134
+ function openLogModal(index) {
135
+ const modal = document.getElementById('log-modal');
136
+ modal.style.display = 'flex';
137
+
138
+ const form = document.getElementById('log-form');
139
+ form.onsubmit = e => {
140
+ e.preventDefault();
141
+ const amount = parseInt(document.getElementById('usage-amount').value);
142
+ const desc = document.getElementById('usage-description').value.trim();
143
+
144
+ if (amount < 1 || !desc) return alert('Please fill all fields correctly.');
145
+
146
+ services[index].currentUsage = (services[index].currentUsage || 0) + amount;
147
+
148
+ history.push({
149
+ service: services[index].name,
150
+ amount,
151
+ description: desc,
152
+ timestamp: new Date().toISOString()
153
+ });
154
+
155
+ saveData();
156
+ renderServices();
157
+ renderHistory();
158
+ closeModal();
159
+ };
160
+ }
161
+
162
+ function closeModal() {
163
+ document.getElementById('log-modal').style.display = 'none';
164
+ document.getElementById('log-form').reset();
165
+ }
166
+
167
+ document.getElementById('add-service-form').addEventListener('submit', e => {
168
+ e.preventDefault();
169
+ const name = document.getElementById('service-name').value.trim();
170
+ const limit = parseInt(document.getElementById('limit').value);
171
+ const period = document.getElementById('refresh-period').value;
172
+
173
+ if (!name || limit < 1) return alert('Please enter valid name and limit.');
174
+
175
+ services.push({
176
+ name,
177
+ limit,
178
+ refreshPeriod: period,
179
+ refreshTime: calculateRefreshTime(period).toISOString(),
180
+ currentUsage: 0
181
+ });
182
+
183
+ saveData();
184
+ renderServices();
185
+ e.target.reset();
186
+ });
187
+
188
+ // Routing
189
+ function handleRoute() {
190
+ const hash = location.hash.slice(1) || 'dashboard';
191
+ document.querySelectorAll('.container > section').forEach(sec => {
192
+ sec.style.display = sec.id === hash ? 'block' : 'none';
193
+ });
194
+ if (hash === 'history') renderHistory();
195
+ }
196
+
197
+ window.addEventListener('hashchange', handleRoute);
198
+ window.addEventListener('load', () => {
199
+ renderServices();
200
+ handleRoute();
201
+ });
styles.css ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :root {
2
+ --hf-orange: #f97316;
3
+ --hf-yellow: #fbbf24;
4
+ --text-dark: #0f172a;
5
+ --text-muted: #475569;
6
+ --bg-light: #f8f9fa;
7
+ --card-bg: #ffffff;
8
+ --border: #e2e8f0;
9
+ }
10
+
11
+ * {
12
+ box-sizing: border-box;
13
+ }
14
+
15
+ body {
16
+ font-family: 'Inter', system-ui, sans-serif;
17
+ margin: 0;
18
+ padding: 0;
19
+ background-color: var(--bg-light);
20
+ color: var(--text-dark);
21
+ line-height: 1.6;
22
+ }
23
+
24
+ .navbar {
25
+ background: white;
26
+ border-bottom: 1px solid var(--border);
27
+ padding: 1rem 2rem;
28
+ display: flex;
29
+ justify-content: space-between;
30
+ align-items: center;
31
+ box-shadow: 0 1px 3px rgba(0,0,0,0.05);
32
+ }
33
+
34
+ .logo {
35
+ font-size: 1.6rem;
36
+ font-weight: 700;
37
+ color: var(--hf-orange);
38
+ }
39
+
40
+ .logo i {
41
+ margin-right: 0.5rem;
42
+ }
43
+
44
+ .nav-links {
45
+ display: flex;
46
+ gap: 2rem;
47
+ }
48
+
49
+ .nav-links a {
50
+ color: var(--text-muted);
51
+ text-decoration: none;
52
+ font-weight: 500;
53
+ display: flex;
54
+ align-items: center;
55
+ gap: 0.5rem;
56
+ transition: color 0.2s;
57
+ }
58
+
59
+ .nav-links a:hover {
60
+ color: var(--hf-orange);
61
+ }
62
+
63
+ .container {
64
+ max-width: 1280px;
65
+ margin: 0 auto;
66
+ padding: 2rem 1rem;
67
+ }
68
+
69
+ .section-title {
70
+ font-size: 2.25rem;
71
+ font-weight: 800;
72
+ margin-bottom: 1.5rem;
73
+ color: var(--text-dark);
74
+ }
75
+
76
+ .cards {
77
+ display: grid;
78
+ grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
79
+ gap: 1.75rem;
80
+ }
81
+
82
+ .card {
83
+ background: var(--card-bg);
84
+ border: 1px solid var(--border);
85
+ border-radius: 0.75rem;
86
+ padding: 1.5rem;
87
+ box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
88
+ transition: transform 0.2s, box-shadow 0.2s;
89
+ }
90
+
91
+ .card:hover {
92
+ transform: translateY(-4px);
93
+ box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
94
+ }
95
+
96
+ .card-title {
97
+ font-size: 1.35rem;
98
+ font-weight: 700;
99
+ margin-bottom: 1rem;
100
+ display: flex;
101
+ align-items: center;
102
+ gap: 0.75rem;
103
+ color: var(--text-dark);
104
+ }
105
+
106
+ .card-title i {
107
+ color: var(--hf-orange);
108
+ font-size: 1.4rem;
109
+ }
110
+
111
+ .progress-container {
112
+ margin: 1.25rem 0;
113
+ }
114
+
115
+ .progress-bar {
116
+ background: #e2e8f0;
117
+ border-radius: 9999px;
118
+ height: 0.75rem;
119
+ overflow: hidden;
120
+ }
121
+
122
+ .progress-fill {
123
+ height: 100%;
124
+ transition: width 0.4s ease;
125
+ }
126
+
127
+ .progress-text {
128
+ font-size: 0.95rem;
129
+ color: var(--text-muted);
130
+ margin-top: 0.5rem;
131
+ text-align: center;
132
+ font-weight: 500;
133
+ }
134
+
135
+ .chart-container {
136
+ height: 160px;
137
+ margin: 1rem 0;
138
+ }
139
+
140
+ .button {
141
+ padding: 0.65rem 1.25rem;
142
+ border: none;
143
+ border-radius: 0.5rem;
144
+ font-weight: 600;
145
+ cursor: pointer;
146
+ display: inline-flex;
147
+ align-items: center;
148
+ gap: 0.5rem;
149
+ transition: all 0.2s;
150
+ }
151
+
152
+ .button.primary {
153
+ background: var(--hf-yellow);
154
+ color: var(--text-dark);
155
+ }
156
+
157
+ .button.primary:hover {
158
+ background: var(--hf-orange);
159
+ color: white;
160
+ }
161
+
162
+ .button.secondary {
163
+ background: var(--text-muted);
164
+ color: white;
165
+ }
166
+
167
+ .button.secondary:hover {
168
+ background: #334155;
169
+ }
170
+
171
+ .form-group {
172
+ margin-bottom: 1.25rem;
173
+ }
174
+
175
+ .form-group label {
176
+ display: block;
177
+ margin-bottom: 0.5rem;
178
+ font-weight: 500;
179
+ color: var(--text-dark);
180
+ }
181
+
182
+ .form-group input,
183
+ .form-group select {
184
+ width: 100%;
185
+ padding: 0.75rem 1rem;
186
+ border: 1px solid #cbd5e1;
187
+ border-radius: 0.5rem;
188
+ font-size: 1rem;
189
+ background: #f8fafc;
190
+ }
191
+
192
+ #history-list {
193
+ list-style: none;
194
+ padding: 0;
195
+ }
196
+
197
+ #history-list li {
198
+ background: white;
199
+ border: 1px solid var(--border);
200
+ border-radius: 0.5rem;
201
+ padding: 1.25rem;
202
+ margin-bottom: 1rem;
203
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
204
+ }
205
+
206
+ .modal {
207
+ display: none;
208
+ position: fixed;
209
+ inset: 0;
210
+ background: rgba(0,0,0,0.5);
211
+ z-index: 1000;
212
+ align-items: center;
213
+ justify-content: center;
214
+ }
215
+
216
+ .modal-content {
217
+ background: white;
218
+ width: 90%;
219
+ max-width: 480px;
220
+ border-radius: 0.75rem;
221
+ padding: 1.75rem;
222
+ box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
223
+ position: relative;
224
+ }
225
+
226
+ .close {
227
+ position: absolute;
228
+ right: 1.25rem;
229
+ top: 1rem;
230
+ font-size: 2rem;
231
+ color: #94a3b8;
232
+ cursor: pointer;
233
+ }
234
+
235
+ .close:hover {
236
+ color: #1e293b;
237
+ }
238
+
239
+ @media (max-width: 640px) {
240
+ .navbar {
241
+ flex-direction: column;
242
+ gap: 1rem;
243
+ padding: 1.25rem;
244
+ }
245
+ .nav-links {
246
+ flex-wrap: wrap;
247
+ justify-content: center;
248
+ }
249
+ }