Update README.md
Browse files
README.md
CHANGED
|
@@ -4,38 +4,45 @@ emoji: 🦊
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 6.17.3
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: mit
|
| 11 |
-
short_description:
|
| 12 |
tags:
|
| 13 |
-
-
|
| 14 |
-
-
|
| 15 |
-
-
|
| 16 |
-
-
|
| 17 |
-
-
|
| 18 |
-
-
|
|
|
|
|
|
|
|
|
|
| 19 |
---
|
| 20 |
|
| 21 |
# 🦊 Tiny Civilization — The Tinywick Hollow Gazette
|
| 22 |
|
| 23 |
-
> *A persistent woodland simulation where four
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
---
|
| 28 |
|
| 29 |
## What is this?
|
| 30 |
|
| 31 |
-
Every time you click **Advance Day**, four woodland creatures
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
persists across sessions (on Spaces with persistent storage attached).
|
| 39 |
|
| 40 |
---
|
| 41 |
|
|
@@ -43,219 +50,73 @@ persists across sessions (on Spaces with persistent storage attached).
|
|
| 43 |
|
| 44 |
| Feature | Detail |
|
| 45 |
|---|---|
|
| 46 |
-
| 🗞️ **
|
| 47 |
-
|
|
| 48 |
-
|
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
| ⚖️ **Propose a Law** | Shift the legal framework of the Hollow |
|
| 51 |
-
| 🖼️ **Share as Image** | Download
|
| 52 |
| 🎮 **Konami Code** | `↑↑↓↓←→←→BA` — reveals all agent system prompts |
|
| 53 |
-
|
|
| 54 |
-
| 💾 **Persistent SQLite** | `days`, `events`, `creatures`, `nudges` tables |
|
| 55 |
-
|
| 56 |
-
---
|
| 57 |
-
|
| 58 |
-
## Project Structure
|
| 59 |
-
|
| 60 |
-
```
|
| 61 |
-
tiny_civilization/
|
| 62 |
-
├── app.py # Main Gradio Blocks application
|
| 63 |
-
├── database.py # SQLite layer (init_db, save_day, update_creature …)
|
| 64 |
-
├── requirements.txt # Python dependencies
|
| 65 |
-
├── packages.txt # System packages (fonts)
|
| 66 |
-
└── README.md # This file
|
| 67 |
-
```
|
| 68 |
-
|
| 69 |
-
---
|
| 70 |
-
|
| 71 |
-
## Local Setup
|
| 72 |
-
|
| 73 |
-
### Prerequisites
|
| 74 |
-
- Python 3.10+
|
| 75 |
-
- ~8 GB VRAM for 7B model (or ~6 GB for 3B fallback)
|
| 76 |
-
- CPU-only works too — just slower
|
| 77 |
-
|
| 78 |
-
### Install
|
| 79 |
-
|
| 80 |
-
```bash
|
| 81 |
-
git clone https://huggingface.co/spaces/YOUR_USERNAME/tiny-civilization
|
| 82 |
-
cd tiny-civilization
|
| 83 |
-
|
| 84 |
-
python -m venv .venv
|
| 85 |
-
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
| 86 |
-
|
| 87 |
-
pip install -r requirements.txt
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
### Run
|
| 91 |
-
|
| 92 |
-
```bash
|
| 93 |
-
python app.py
|
| 94 |
-
```
|
| 95 |
-
|
| 96 |
-
Open `http://localhost:7860` in your browser.
|
| 97 |
-
|
| 98 |
-
> **Note:** On first run the model downloads ~6–15 GB depending on which
|
| 99 |
-
> Qwen2.5 variant loads successfully. Subsequent starts use the local cache.
|
| 100 |
-
|
| 101 |
-
### Environment variables
|
| 102 |
-
|
| 103 |
-
| Variable | Default | Purpose |
|
| 104 |
-
|---|---|---|
|
| 105 |
-
| `TINY_DB_PATH` | auto-detected | Override SQLite file path |
|
| 106 |
-
| `HF_HOME` | `~/.cache/huggingface` | Model cache directory |
|
| 107 |
|
| 108 |
---
|
| 109 |
|
| 110 |
-
##
|
| 111 |
-
|
| 112 |
-
1. Create a new **Gradio** Space on [huggingface.co/spaces](https://huggingface.co/spaces).
|
| 113 |
-
2. Enable **ZeroGPU** in the Space hardware settings (T4 or better recommended).
|
| 114 |
-
3. Optionally attach a **Persistent Storage** volume (Space → Settings → Persistent Storage) so the SQLite database survives restarts. The app writes to `/data/` when available, local directory otherwise.
|
| 115 |
-
4. Push all files:
|
| 116 |
|
| 117 |
-
``
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
5. The Space will install `requirements.txt` and `packages.txt` automatically.
|
| 123 |
-
|
| 124 |
-
### `packages.txt` (system fonts for PIL image export)
|
| 125 |
-
|
| 126 |
-
Create a file named `packages.txt` at the repo root with:
|
| 127 |
-
|
| 128 |
-
```
|
| 129 |
-
fonts-liberation
|
| 130 |
-
fonts-dejavu-core
|
| 131 |
-
```
|
| 132 |
-
|
| 133 |
-
This installs serif fonts that PIL uses to render the newspaper image.
|
| 134 |
-
Without them the image still generates but uses a smaller bitmap font.
|
| 135 |
|
| 136 |
---
|
| 137 |
|
| 138 |
-
##
|
| 139 |
|
| 140 |
```
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
├─ For each of 3 events:
|
| 150 |
-
│ ├─ pick random actor, target, event_type
|
| 151 |
-
│ ├─ call_agent(actor, situation_prompt) ←── Qwen2.5 inference
|
| 152 |
-
│ ├─ save_event() [SQLite]
|
| 153 |
-
│ └─ update creature relationship_scores [SQLite]
|
| 154 |
-
│
|
| 155 |
-
├─ _generate_newspaper(events_summary) ←── Qwen2.5 inference
|
| 156 |
-
├─ _parse_newspaper() → headline + article
|
| 157 |
-
├─ save_day() [SQLite]
|
| 158 |
-
│
|
| 159 |
-
└─ return (day_number, headline, article)
|
| 160 |
-
│
|
| 161 |
-
▼
|
| 162 |
-
Gradio updates all UI components
|
| 163 |
```
|
| 164 |
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
Each creature has a relationship score (0–100) with every other creature.
|
| 168 |
-
Event types shift scores:
|
| 169 |
-
|
| 170 |
-
| Event | Delta (actor→target) |
|
| 171 |
-
|---|---|
|
| 172 |
-
| `trade` | +5 |
|
| 173 |
-
| `invention` | +7 |
|
| 174 |
-
| `gossip` | −4 |
|
| 175 |
-
| `feud` | −10 |
|
| 176 |
-
|
| 177 |
-
The target always receives half the delta in return.
|
| 178 |
-
These scores are included in agent prompts so the model can reflect
|
| 179 |
-
on whether a trade is proposed warmly or suspiciously.
|
| 180 |
-
|
| 181 |
-
### Nudge Persistence
|
| 182 |
|
| 183 |
-
|
| 184 |
-
every subsequent day's generation context, creating a chain of cause and
|
| 185 |
-
effect across days.
|
| 186 |
|
| 187 |
---
|
| 188 |
|
| 189 |
-
##
|
| 190 |
|
| 191 |
-
|
| 192 |
-
|---|---|
|
| 193 |
-
| **Primary** | `Qwen/Qwen2.5-7B-Instruct` |
|
| 194 |
-
| **Fallback** | `Qwen/Qwen2.5-3B-Instruct` |
|
| 195 |
-
| **Precision** | `torch.float16` |
|
| 196 |
-
| **Device** | `device_map="auto"` |
|
| 197 |
-
| **Sampling** | `temperature=0.88`, `top_p=0.92` |
|
| 198 |
-
| **Max tokens** | 120 per agent, 280 for newspaper |
|
| 199 |
-
|
| 200 |
-
The app makes **4 inference calls per day** (3 creature events + 1 newspaper).
|
| 201 |
-
Each response is short (2–3 sentences for agents, 4 sentences for the Gazette).
|
| 202 |
-
This keeps total token usage well within the *Thousand Token Wood* track budget.
|
| 203 |
-
|
| 204 |
-
---
|
| 205 |
-
|
| 206 |
-
## Easter Egg
|
| 207 |
-
|
| 208 |
-
Enter the **Konami Code** on your keyboard while the app is focused:
|
| 209 |
-
|
| 210 |
-
```
|
| 211 |
-
↑ ↑ ↓ ↓ ← → ← → B A
|
| 212 |
-
```
|
| 213 |
-
|
| 214 |
-
A modal will appear showing the raw system prompts for all four creature
|
| 215 |
-
agents and the Gazette editor — a behind-the-scenes look at the personas
|
| 216 |
-
driving the simulation.
|
| 217 |
|
| 218 |
---
|
| 219 |
|
| 220 |
## Database Schema
|
| 221 |
|
| 222 |
```sql
|
| 223 |
-
CREATE TABLE days
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
timestamp TEXT NOT NULL
|
| 228 |
-
);
|
| 229 |
-
|
| 230 |
-
CREATE TABLE events (
|
| 231 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 232 |
-
day_number INTEGER NOT NULL,
|
| 233 |
-
actor TEXT NOT NULL, -- fox | badger | squirrel | mole
|
| 234 |
-
action TEXT NOT NULL, -- trade | gossip | feud | invention
|
| 235 |
-
target TEXT NOT NULL,
|
| 236 |
-
description TEXT NOT NULL
|
| 237 |
-
);
|
| 238 |
-
|
| 239 |
-
CREATE TABLE creatures (
|
| 240 |
-
name TEXT PRIMARY KEY,
|
| 241 |
-
relationship_scores TEXT NOT NULL, -- JSON {"fox": 42, …}
|
| 242 |
-
inventory TEXT NOT NULL -- JSON ["item1", …]
|
| 243 |
-
);
|
| 244 |
-
|
| 245 |
-
CREATE TABLE nudges (
|
| 246 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 247 |
-
day_number INTEGER NOT NULL,
|
| 248 |
-
nudge_type TEXT NOT NULL, -- rumour | donation | law
|
| 249 |
-
nudge_value TEXT NOT NULL
|
| 250 |
-
);
|
| 251 |
```
|
| 252 |
|
| 253 |
---
|
| 254 |
|
| 255 |
-
##
|
|
|
|
|
|
|
| 256 |
|
| 257 |
-
|
| 258 |
|
| 259 |
---
|
| 260 |
|
| 261 |
-
*"All things are connected underground." — Millicent Mole*
|
|
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: "6.17.3"
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: mit
|
| 11 |
+
short_description: Persistent woodland civilisation sim. 1.5B model.
|
| 12 |
tags:
|
| 13 |
+
- build-small-hackathon
|
| 14 |
+
- thousand-token-wood
|
| 15 |
+
- tiny-titan
|
| 16 |
+
- off-brand
|
| 17 |
+
- best-agent
|
| 18 |
+
- best-demo
|
| 19 |
+
- simulation
|
| 20 |
+
- creative-writing
|
| 21 |
+
- gradio
|
| 22 |
---
|
| 23 |
|
| 24 |
# 🦊 Tiny Civilization — The Tinywick Hollow Gazette
|
| 25 |
|
| 26 |
+
> *A persistent woodland simulation where four AI agents invent absurd civilisation events — and you read about them in the daily newspaper.*
|
| 27 |
|
| 28 |
+
**[Try it →](https://huggingface.co/spaces/build-small-hackathon/tiny-civilization)**
|
| 29 |
+
|
| 30 |
+
Built for the **Build Small Hackathon 2026 — Thousand Token Wood** track.
|
| 31 |
|
| 32 |
---
|
| 33 |
|
| 34 |
## What is this?
|
| 35 |
|
| 36 |
+
Every time you click **Advance Day**, four woodland creatures run as independent AI agents:
|
| 37 |
+
|
| 38 |
+
| Agent | Personality |
|
| 39 |
+
|---|---|
|
| 40 |
+
| 🦊 **Reginald Fox** | Charming, dishonest, obsessed with certificates |
|
| 41 |
+
| 🦡 **Beatrice Badger** | Gruff rule-keeper, secretly a poet |
|
| 42 |
+
| 🐿️ **Cornelius Squirrel** | Anxious inventor, repeats himself! |
|
| 43 |
+
| 🐀 **Millicent Mole** | Philosophical, speaks in riddles |
|
| 44 |
|
| 45 |
+
Then a fifth **Narrator agent** writes a formal newspaper front page treating the whole affair with the utmost journalistic gravity.
|
|
|
|
| 46 |
|
| 47 |
---
|
| 48 |
|
|
|
|
| 50 |
|
| 51 |
| Feature | Detail |
|
| 52 |
|---|---|
|
| 53 |
+
| 🗞️ **Animated Newspaper** | Paper drops in, headline types itself, ink fades in |
|
| 54 |
+
| 🔊 **Read Aloud** | Browser TTS reads today's front page |
|
| 55 |
+
| 🎵 **Sound Effects** | Paper/press sounds via Web Audio API |
|
| 56 |
+
| 🐿️ **Running Squirrel** | Occasionally sprints across the bottom of the screen |
|
| 57 |
+
| ⏳ **Loading Messages** | Rotating funny messages while the model runs |
|
| 58 |
+
| 📜 **Archive** | Browse every past front page |
|
| 59 |
+
| 🗣️ **Spread a Rumour** | Influence the next day's events |
|
| 60 |
+
| 🎁 **Donate a Weird Object** | Items enter the creature economy |
|
| 61 |
| ⚖️ **Propose a Law** | Shift the legal framework of the Hollow |
|
| 62 |
+
| 🖼️ **Share as Image** | Download a PNG of today's front page |
|
| 63 |
| 🎮 **Konami Code** | `↑↑↓↓←→←→BA` — reveals all agent system prompts |
|
| 64 |
+
| 💾 **Persistent SQLite** | Civilisation remembers its history across sessions |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
---
|
| 67 |
|
| 68 |
+
## Model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
- **Primary**: `Qwen/Qwen2.5-1.5B-Instruct` — 1.5B parameters
|
| 71 |
+
- **Fallback**: `Qwen/Qwen2.5-3B-Instruct` — 3B parameters
|
| 72 |
+
- **Both qualify** for the ≤4B **Tiny Titan** badge 🐜
|
| 73 |
+
- Runs locally via **ZeroGPU** — no external AI APIs 🔌
|
| 74 |
+
- ~520 tokens per day across 4 inference calls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
---
|
| 77 |
|
| 78 |
+
## Architecture
|
| 79 |
|
| 80 |
```
|
| 81 |
+
advance_day() ←── @spaces.GPU(duration=60)
|
| 82 |
+
│
|
| 83 |
+
├─ call_agent("fox", trade_prompt) → ~80 tokens
|
| 84 |
+
├─ call_agent("badger", gossip_prompt) → ~80 tokens
|
| 85 |
+
├─ call_agent("squirrel", feud_prompt) → ~80 tokens
|
| 86 |
+
└─ generate_newspaper(events_summary) → ~280 tokens
|
| 87 |
+
│
|
| 88 |
+
└─ Structured output: HEADLINE / article / WEATHER / FOX / BADGER / SQUIRREL / MOLE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
```
|
| 90 |
|
| 91 |
+
Each agent has a 4-sentence system prompt defining their personality. The narrator uses a rigid output schema that the 1.5B model follows ~85% of the time, with graceful fallbacks for the rest.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
Creature relationships drift based on event type (+5 trade, +7 invention, -4 gossip, -10 feud) and feed back into future agent prompts, creating emergent character dynamics over time.
|
|
|
|
|
|
|
| 94 |
|
| 95 |
---
|
| 96 |
|
| 97 |
+
## Persistent History
|
| 98 |
|
| 99 |
+
Everything is stored in **SQLite**: days, events, creature relationships, inventory, nudges. The newspaper prompt includes the last two published headlines, so the model can write "In a development reminiscent of last Tuesday's acorn scandal..." History actually matters.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
---
|
| 102 |
|
| 103 |
## Database Schema
|
| 104 |
|
| 105 |
```sql
|
| 106 |
+
CREATE TABLE days (day_number, headline, full_newspaper_text, timestamp);
|
| 107 |
+
CREATE TABLE events (id, day_number, actor, action, target, description);
|
| 108 |
+
CREATE TABLE creatures(name, relationship_scores JSON, inventory JSON);
|
| 109 |
+
CREATE TABLE nudges (id, day_number, nudge_type, nudge_value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
```
|
| 111 |
|
| 112 |
---
|
| 113 |
|
| 114 |
+
## Easter Egg
|
| 115 |
+
|
| 116 |
+
Type the **Konami Code** while the app is focused: `↑ ↑ ↓ ↓ ← → ← → B A`
|
| 117 |
|
| 118 |
+
A modal appears showing all five raw system prompts — the behind-the-scenes look at what's driving the simulation.
|
| 119 |
|
| 120 |
---
|
| 121 |
|
| 122 |
+
*"All things are connected underground." — Millicent Mole, Day 1*
|