PeterPinetree commited on
Commit
24f1efd
ยท
1 Parent(s): 020a95f

Update README and requirements for consistency and accuracy

Browse files
Files changed (2) hide show
  1. README.md +6 -406
  2. requirements.txt +1 -1
README.md CHANGED
@@ -1,411 +1,11 @@
1
- ---# Next-Token Predictor# Next-Token Predictor# Next-Token Predictor---
2
-
3
- title: Next-Token Predictor
4
-
5
  emoji: ๐Ÿ”ฎ
6
-
7
  colorFrom: indigo
8
-
9
- colorTo: purpleA clean, modern web app that demonstrates how AI language models predict the next word in a sequence. Built with Gradio for easy deployment and secure token management.
10
-
11
  sdk: gradio
12
-
13
- sdk_version: 4.44.0
14
-
15
  app_file: app.py
16
-
17
- pinned: false![Demo](https://img.shields.io/badge/Demo-Live-brightgreen) ![Python](https://img.shields.io/badge/Python-3.8+-blue) ![Gradio](https://img.shields.io/badge/Gradio-4.44+-orange)A clean, modern web app that demonstrates how AI language models predict the next word in a sequence. Built with Gradio for easy deployment and secure token management.title:# Next-Token Predictor
18
-
19
  short_description: Demonstrate how AI language models predict the next word in a sequence
20
-
21
- ---
22
-
23
-
24
-
25
- # Next-Token Predictor## โœจ Features
26
-
27
-
28
-
29
- A clean, modern web app that demonstrates how AI language models predict the next word in a sequence. Built with Gradio for easy deployment and secure token management.
30
-
31
-
32
-
33
- ![Demo](https://img.shields.io/badge/Demo-Live-brightgreen) ![Python](https://img.shields.io/badge/Python-3.8+-blue) ![Gradio](https://img.shields.io/badge/Gradio-4.44+-orange)- **๐Ÿ”ฎ Real-time Predictions**: Updates automatically as you type![Demo](https://img.shields.io/badge/Demo-Live-brightgreen) ![Python](https://img.shields.io/badge/Python-3.8+-blue) ![Gradio](https://img.shields.io/badge/Gradio-4.44+-orange)A clean, modern web app that demonstrates how AI language models predict the next word in a sequence. Built with Gradio for easy deployment and secure token management.
34
-
35
-
36
-
37
- ## โœจ Features- **๐Ÿ”’ Secure**: Uses environment variables for API tokens
38
-
39
-
40
-
41
- - **๐Ÿ”ฎ Real-time Predictions**: Updates automatically as you type- **โšก Fast**: Serverless API calls with instant results
42
-
43
- - **๐Ÿ”’ Secure**: Uses environment variables for API tokens
44
-
45
- - **โšก Fast**: Serverless API calls with instant results- **๐Ÿ“ฑ Responsive**: Clean, mobile-friendly interface
46
-
47
- - **๐Ÿ“ฑ Responsive**: Clean, mobile-friendly interface
48
-
49
- - **๐Ÿš€ Easy Deploy**: One-click deployment to HF Spaces- **๐Ÿš€ Easy Deploy**: One-click deployment to HF Spaces## โœจ Features๐ŸŽฏ **Note**: This project has been converted to a Gradio app! See `README-gradio.md` for the latest version.
50
-
51
-
52
-
53
- ## ๐Ÿš€ Quick Start
54
-
55
-
56
-
57
- 1. **Install dependencies:**## ๐Ÿš€ Quick Start
58
-
59
- ```bash
60
-
61
- pip install -r requirements.txt
62
-
63
- ```
64
-
65
- 1. **Install dependencies:**- **๐Ÿ”ฎ Real-time Predictions**: Updates automatically as you type![Demo](https://img.shields.io/badge/Demo-Live-brightgreen) ![Python](https://img.shields.io/badge/Python-3.8+-blue) ![Gradio](https://img.shields.io/badge/Gradio-4.44+-orange)
66
-
67
- 2. **Set your HF token:**
68
-
69
- ```bash
70
-
71
- **Option A: Using .env file (Recommended for local development)**
72
-
73
- ```bash pip install -r requirements.txt- **๐Ÿ”’ Secure**: Uses environment variables for API tokens
74
-
75
- # Copy the template
76
-
77
- cp .env.example .env ```
78
-
79
-
80
-
81
- # Edit .env and add your token:- **โšก Fast**: Serverless API calls with instant resultsA web application that demonstrates how AI language models predict the next word in a sequence. Originally built with HTML/JavaScript, now available as a streamlined Gradio app for easier deployment and better security.
82
-
83
- # HF_NEXT_TOKEN_PREDICTOR_TOKEN=hf_your_actual_token_here
84
-
85
- ```2. **Set your HF token:**
86
-
87
-
88
-
89
- **Option B: Using environment variable** - **๐Ÿ“ฑ Responsive**: Clean, mobile-friendly interface
90
-
91
- ```bash
92
-
93
- export HF_NEXT_TOKEN_PREDICTOR_TOKEN="hf_your_token_here" # Linux/Mac **Option A: Using .env file (Recommended for local development)**
94
-
95
- $env:HF_NEXT_TOKEN_PREDICTOR_TOKEN="hf_your_token_here" # Windows PowerShell
96
-
97
- ``` ```bash- **๐Ÿš€ Easy Deploy**: One-click deployment to HF Spaces## โœจ Features
98
-
99
-
100
-
101
- 3. **Run the app:** # Copy the template
102
-
103
- ```bash
104
-
105
- python app.py cp .env.example .env
106
-
107
- ```
108
-
109
-
110
-
111
- 4. **Open browser:** Navigate to `http://127.0.0.1:7860`
112
-
113
- # Edit .env and add your token:## ๐Ÿš€ Quick Start## ๐Ÿš€ Quick Start
114
-
115
- ## ๐Ÿ”ง Deploy to HF Spaces
116
-
117
- # HF_NEXT_TOKEN_PREDICTOR_TOKEN=hf_your_actual_token_here
118
-
119
- 1. Create a new **Gradio Space** on Hugging Face
120
-
121
- 2. Upload `app.py` and `requirements.txt` ```
122
-
123
- 3. Set `HF_NEXT_TOKEN_PREDICTOR_TOKEN` as a **repository secret** (not as .env file)
124
-
125
- 4. Your demo is live! โœจ
126
-
127
-
128
-
129
- ## ๐Ÿ’ฐ Cost **Option B: Using environment variable**1. **Install dependencies:**- **๐Ÿ”ฎ Real-time Predictions**: Updates automatically as you type
130
-
131
-
132
-
133
- With HF Pro account ($20/month): ```bash
134
-
135
- - **$2.00/month** in free API calls
136
-
137
- - **~$0.0001** per prediction export HF_NEXT_TOKEN_PREDICTOR_TOKEN="hf_your_token_here" # Linux/Mac ```bash
138
-
139
- - **2,000-20,000** free predictions/month
140
-
141
- $env:HF_NEXT_TOKEN_PREDICTOR_TOKEN="hf_your_token_here" # Windows PowerShell
142
-
143
- ## ๐ŸŽฏ Try It
144
-
145
- ``` pip install -r requirements.txt- **๐Ÿ”’ Secure**: Uses environment variables for API tokens **For the latest Gradio version**, see `README-gradio.md` and run:
146
-
147
- Type "Twinkle, twinkle, little " and watch the AI predict "star"!
148
-
149
-
150
-
151
- The app demonstrates how language models work by showing real-time probability distributions for the next token in any sequence.
152
-
153
- 3. **Run the app:** ```
154
-
155
- ## ๐Ÿ”’ Security Notes
156
-
157
- ```bash
158
-
159
- - **โœ… .env file**: Safe for local development (ignored by git)
160
-
161
- - **โœ… Environment variables**: Work everywhere python app.py- **โšก Fast**: Serverless API calls with instant results```bash
162
-
163
- - **โœ… HF Spaces secrets**: Secure for production deployment
164
-
165
- - **โŒ Never commit**: Your actual token to version control ```
166
-
167
-
168
-
169
- ## ๐Ÿ“ Project Structure2. **Set your HF token:**
170
-
171
-
172
-
173
- ```4. **Open browser:** Navigate to `http://127.0.0.1:7860`
174
-
175
- โ”œโ”€โ”€ app.py # Main Gradio application
176
-
177
- โ”œโ”€โ”€ requirements.txt # Python dependencies - **๐Ÿ“ฑ Responsive**: Clean, mobile-friendly interfacepython app.py
178
-
179
- โ”œโ”€โ”€ .env.example # Template for environment variables
180
-
181
- โ”œโ”€โ”€ .env # Your actual tokens (git ignored)## ๐Ÿ”ง Deploy to HF Spaces
182
-
183
- โ”œโ”€โ”€ .gitignore # Protects secrets from being committed
184
-
185
- โ””โ”€โ”€ README.md # This file **Option A: Using .env file (Recommended for local development)**
186
-
187
- ```
188
-
189
- 1. Create a new **Gradio Space** on Hugging Face
190
-
191
- ## ๐Ÿค Contributing
192
-
193
- 2. Upload `app.py` and `requirements.txt` ```bash- **๐Ÿš€ Easy Deploy**: One-click deployment to HF Spaces```
194
-
195
- Feel free to improve the API parsing, add features, or enhance the design!
196
- 3. Set `HF_NEXT_TOKEN_PREDICTOR_TOKEN` as a **repository secret** (not as .env file)
197
-
198
- 4. Your demo is live! โœจ # Copy the template
199
-
200
-
201
-
202
- ## ๐Ÿ’ฐ Cost cp .env.example .env
203
-
204
-
205
-
206
- With HF Pro account ($20/month):
207
-
208
- - **$2.00/month** in free API calls
209
-
210
- - **~$0.0001** per prediction # Edit .env and add your token:## ๐Ÿš€ Quick Start**For the original HTML version**, see below:
211
-
212
- - **2,000-20,000** free predictions/month
213
-
214
- # HF_TOKEN=hf_your_actual_token_here
215
-
216
- ## ๐ŸŽฏ Try It
217
-
218
- ```
219
-
220
- Type "Twinkle, twinkle, little " and watch the AI predict "star"!
221
-
222
-
223
-
224
- The app demonstrates how language models work by showing real-time probability distributions for the next token in any sequence.
225
-
226
- **Option B: Using environment variable**1. **Install dependencies:**---
227
-
228
- ## ๐Ÿ”’ Security Notes
229
-
230
- ```bash
231
-
232
- - **โœ… .env file**: Safe for local development (ignored by git)
233
-
234
- - **โœ… Environment variables**: Work everywhere export HF_TOKEN="hf_your_token_here" # Linux/Mac ```bash
235
-
236
- - **โœ… HF Spaces secrets**: Secure for production deployment
237
-
238
- - **โŒ Never commit**: Your actual token to version control $env:HF_TOKEN="hf_your_token_here" # Windows PowerShell
239
-
240
-
241
-
242
- ## ๐Ÿ“ Project Structure ``` pip install -r requirements.txt## Original HTML VersionNext Token Predictor
243
-
244
-
245
-
246
- ```
247
-
248
- โ”œโ”€โ”€ app.py # Main Gradio application
249
-
250
- โ”œโ”€โ”€ requirements.txt # Python dependencies3. **Run the app:** ```emoji: ๐Ÿ”ฎ
251
-
252
- โ”œโ”€โ”€ .env.example # Template for environment variables
253
-
254
- โ”œโ”€โ”€ .env # Your actual tokens (git ignored) ```bash
255
-
256
- โ”œโ”€โ”€ .gitignore # Protects secrets from being committed
257
-
258
- โ””โ”€โ”€ README.md # This file python app.pycolorFrom: gray
259
-
260
- ```
261
-
262
- ```
263
-
264
- ## ๐Ÿค Contributing
265
-
266
- 2. **Set your HF token:**colorTo: blue
267
-
268
- Feel free to improve the API parsing, add features, or enhance the design!
269
- 4. **Open browser:** Navigate to `http://127.0.0.1:7860`
270
-
271
- ```bashsdk: static
272
-
273
- ## ๐Ÿ”ง Deploy to HF Spaces
274
-
275
- export HF_TOKEN="hf_your_token_here"pinned: false
276
-
277
- 1. Create a new **Gradio Space** on Hugging Face
278
-
279
- 2. Upload `app.py` and `requirements.txt` ```license: mit
280
-
281
- 3. Set `HF_TOKEN` as a **repository secret** (not as .env file)
282
-
283
- 4. Your demo is live! โœจshort_description: See how AI predicts the next token and explore semantic relationships
284
-
285
-
286
-
287
- ## ๐Ÿ’ฐ Cost3. **Run the app:**---
288
-
289
-
290
-
291
- With HF Pro account ($20/month): ```bash
292
-
293
- - **$2.00/month** in free API calls
294
-
295
- - **~$0.0001** per prediction python app.py# Next Token Predictor
296
-
297
- - **2,000-20,000** free predictions/month
298
-
299
- ```
300
-
301
- ## ๐ŸŽฏ Try It
302
-
303
- Explore how AI language models think! This interactive demo shows how a large language model predicts the next token in a sentence, and visualizes token relationships in a semantic space that mimics neural connections in the brain.
304
-
305
- Type "Twinkle, twinkle, little " and watch the AI predict "star"!
306
-
307
- 4. **Open browser:** Navigate to `http://127.0.0.1:7860`
308
-
309
- The app demonstrates how language models work by showing real-time probability distributions for the next token in any sequence.
310
-
311
- ## Features
312
-
313
- ## ๐Ÿ”’ Security Notes
314
-
315
- ## ๐Ÿ”ง Deploy to HF Spaces
316
-
317
- - **โœ… .env file**: Safe for local development (ignored by git)
318
-
319
- - **โœ… Environment variables**: Work everywhere- **Real-time Token Prediction**: Type any text and see the model's top predictions for the next token
320
-
321
- - **โœ… HF Spaces secrets**: Secure for production deployment
322
-
323
- - **โŒ Never commit**: Your actual token to version control1. Create a new **Gradio Space** on Hugging Face- **Semantic Neighborhood Map**: Interactive 2D visualization of token embeddings, showing how AI associates words
324
-
325
-
326
-
327
- ## ๐Ÿ“ Project Structure2. Upload `app.py` and `requirements.txt`- **Educational Tool**: Designed to teach non-technical users about AI language processing
328
-
329
-
330
-
331
- ```3. Set `HF_TOKEN` as a **repository secret**- **Browser-Based**: Runs entirely in your browser using Hugging Face Serverless Inference API
332
-
333
- โ”œโ”€โ”€ app.py # Main Gradio application
334
-
335
- โ”œโ”€โ”€ requirements.txt # Python dependencies4. Your demo is live! โœจ- **Instant Predictions**: No model downloads - predictions happen instantly via API calls
336
-
337
- โ”œโ”€โ”€ .env.example # Template for environment variables
338
-
339
- โ”œโ”€โ”€ .env # Your actual tokens (git ignored)
340
-
341
- โ”œโ”€โ”€ .gitignore # Protects secrets from being committed
342
-
343
- โ””โ”€โ”€ README.md # This file## ๐Ÿ’ฐ Cost## How It Works
344
-
345
- ```
346
-
347
-
348
-
349
- ## ๐Ÿค Contributing
350
-
351
- With HF Pro account ($20/month):1. **Token Prediction**: The model analyzes your input and predicts the most likely next words/tokens based on its training data
352
-
353
- Feel free to improve the API parsing, add features, or enhance the design!
354
- - **$2.00/month** in free API calls2. **Semantic Map**: Tokens are positioned in 2D space based on their embeddings. Closer tokens are more semantically similar
355
-
356
- - **~$0.0001** per prediction 3. **Neural Connections**: Lines show relationships between tokens, illustrating how AI "thinks" through associations
357
-
358
- - **2,000-20,000** free predictions/month
359
-
360
- ## Usage
361
-
362
- ## ๐ŸŽฏ Try It
363
-
364
- - Enter your Hugging Face API token (Pro account required) in the token field
365
-
366
- Type "Twinkle, twinkle, little " and watch the AI predict "star"! - Type a sentence in the input box
367
-
368
- - View the top predicted tokens on the right
369
-
370
- The app demonstrates how language models work by showing real-time probability distributions for the next token in any sequence.- Click on predictions to append them to your text
371
-
372
- - Hover over tokens in the list to see them highlighted in the semantic map
373
-
374
- ## ๐Ÿ“ Project Structure- Use the "Run Twinkle demo" to see a classic example
375
-
376
-
377
-
378
- ```## Technical Details
379
-
380
- โ”œโ”€โ”€ app.py # Main Gradio application
381
-
382
- โ”œโ”€โ”€ requirements.txt # Python dependencies- **Model**: Qwen3-0.6B via Hugging Face Serverless Inference API
383
-
384
- โ””โ”€โ”€ README.md # This file- **API**: Hugging Face Inference API (requires Pro account token)
385
-
386
- ```- **Performance**: Instant predictions with no model downloads
387
-
388
- - **Embeddings**: Pre-computed PCA projections of Qwen token embeddings for visualization
389
-
390
- ## ๐Ÿค Contributing
391
-
392
- ## Deployment on Hugging Face Spaces
393
-
394
- Feel free to improve the API parsing, add features, or enhance the design!
395
- This project is designed to run as a static space on Hugging Face:
396
-
397
- 1. Create a new Space with "Static" SDK
398
- 2. Upload all files from this repository
399
- 3. The `index.html` serves as the main page
400
- 4. Ensure `assets/` folder is included for embeddings and vendor libraries
401
- 5. The model is fetched directly from the Hugging Face Hub (no local model files needed)
402
-
403
- ## Educational Goals
404
-
405
- This tool helps users understand:
406
- - How AI processes language at the token level
407
- - The concept of embeddings and semantic similarity
408
- - How predictions are made based on statistical patterns
409
- - The "neural network" metaphor through visual connections
410
-
411
- Enjoy exploring AI's "mind"!
 
1
+ ---
2
+ title: Next Token Predictor
 
 
3
  emoji: ๐Ÿ”ฎ
 
4
  colorFrom: indigo
5
+ colorTo: purple
 
 
6
  sdk: gradio
7
+ sdk_version: 4.44.1
 
 
8
  app_file: app.py
9
+ pinned: false
 
 
10
  short_description: Demonstrate how AI language models predict the next word in a sequence
11
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- gradio==4.44.0
2
  requests==2.31.0
3
  python-dotenv==1.0.0
 
1
+ gradio==4.44.1
2
  requests==2.31.0
3
  python-dotenv==1.0.0