Spaces:
Sleeping
Sleeping
File size: 1,712 Bytes
0a85b87 850aa4f |
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 |
---
title: Token Counter
emoji: 👀
colorFrom: pink
colorTo: purple
sdk: gradio
sdk_version: 6.2.0
app_file: app.py
pinned: false
license: mit
---
# Token Counter
A Gradio-based web application for counting tokens in text and web content using OpenAI's tiktoken library.
## Features
### Text Input Mode
- Paste or type text directly into the interface
- Real-time token counting as you type
- Support for multiple OpenAI model encodings (GPT-4.1, GPT-5, O1, O3, O4-mini, embeddings, and more)
- Displays token count and character count
### URL Input Mode
- Fetch and analyze content from any URL
- Counts tokens for both HTML and Markdown representations
- Shows token counts and character counts for both formats
- One-click example URL for testing
- **15-minute response caching** to prevent flooding target URLs with repeated requests
## Supported Models
The tool supports token counting for various OpenAI model families:
- **Reasoning models**: o1, o3, o4-mini
- **Chat models**: gpt-5, gpt-4.1, gpt-4o, gpt-4, gpt-3.5-turbo
- **Embedding models**: text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large
- **Legacy models**: davinci-002, babbage-002
## How It Works
Token counting uses the [tiktoken](https://github.com/openai/tiktoken) library to estimate the number of tokens that would be consumed by different OpenAI models. This is useful for:
- Estimating API costs
- Staying within model token limits
- Optimizing prompts and content
- Comparing token efficiency between HTML and Markdown formats
## Caching
URL responses are cached for 15 minutes to reduce load on target servers. The status message indicates when cached content is being used and how old the cache is.
|