--- title: Tianwen emoji: ๐Ÿ”ฎ colorFrom: indigo colorTo: pink sdk: gradio sdk_version: 6.17.3 python_version: '3.12' app_file: app.py pinned: false license: mit tags: - track:wood - sponsor:openbmb - sponsor:modal - achievement:offgrid - achievement:welltuned - achievement:sharing - achievement:fieldnotes - badge:tiny - minicpm - llama-cpp - on-device --- # ๅคฉ้—ฎ ยท Tianwen **An entirely on-device Eastern self-reflection app โ€” a 1B model that translates 3,000 years of Chinese metaphysical language into one small, doable step for today.** > Built for the **Build Small Hackathon**. Named after Qu Yuan's ancient poem *Tianwen* (ใ€Šๅคฉ้—ฎใ€‹, > "Questions to Heaven") โ€” a reminder that the most worthwhile questions are the ones we ask ourselves. ๐Ÿ”— **Demo video:** [8-min walkthrough](https://huggingface.co/spaces/liuyd-dev/tianwen/resolve/main/video/Tianwen%20Demo%20Video%208min.mp4) ยท ๐Ÿ”— **Social post:** [r/huggingface](https://www.reddit.com/r/huggingface/comments/1u6x7ui/i_finetuned_minicpm51b_to_turn_chinese_astrology/) ยท ๐Ÿค— **Model:** `build-small-hackathon/tianwen-minicpm5-1b` ยท ๐Ÿค— **Dataset:** `build-small-hackathon/tianwen-distill` --- ## What it is Tianwen takes a deeply esoteric domain โ€” Chinese BaZi (ๅ…ซๅญ—) astrology and I-Ching (ๅ…ญ็ˆป) divination โ€” and turns it into a gentle, gamified instrument for **self-reflection**. It never tells fortunes; it reframes ancient symbols as everyday psychological language and always ends with one concrete action. Four readings, from the widest lens to the closest moment: - **ๅ‘ฝ็›˜ Chart** โ€” your whole-life portrait (BaZi four pillars) - **ๅนด่ฟ Year** โ€” this year's tone, plus twelve months one at a time - **ๆ—ฅ็›˜ Today** โ€” today's energy + a daily sigil wallpaper + a 30-day mood trend - **่ฏทไบ‹ Oracle** โ€” toss three coins six times for an I-Ching reading on a question you hold Languages: **็ฎ€ไฝ“ / ็น้ซ” / English**. Themes: Ru-kiln White / Xuanwu Black. Installable PWA. ## The idea & the tech (write-up) The hackathon's thesis is *"the future of AI doesn't have to live in someone else's data center."* Tianwen is a full app where **everything that matters runs on your own machine**: | Layer | How | |---|---| | **Charting** | Deterministic โ€” `lunar-python` computes BaZi / liunian / liuyue / hexagrams locally. No model guesses dates. | | **Interpretation** | A **fine-tuned MiniCPM5-1B** (1B params) served via **llama.cpp**, OpenAI-compatible. Distilled from a teacher model into our house voice (plain, second-person, anti-doom). | | **Safety** | A **deterministic** guardrail (`safety/intercept`) โ€” crisis words trip an instant circuit-breaker to hotlines; ominous symbols are re-mapped to growth language. Never left to a 1B model's probabilities. | | **Fallback** | If the LLM is unreachable, a rules engine still produces a full reading โ€” so it works **offline**. | We didn't prompt our way to the voice โ€” we **taught** it. See the **[Fine-Tuning Field Notes](docs/FINETUNE_REPORT.md)** for the full distillation โ†’ LoRA โ†’ GGUF โ†’ deployment story (and every bug we hit). **Stack:** MiniCPM5-1B ยท LLaMA-Factory (LoRA, bf16) ยท Modal (A100 training) ยท llama.cpp (GGUF Q4_K_M) ยท HF ZeroGPU (inference) ยท FastAPI + Gradio (backend) ยท React + shadcn/ui + Tailwind (frontend) ยท lunar-python. ## Tracks & badges we're going for - **Track โ€” ๐ŸŒฒ Thousand Token Wood**: an esoteric professional domain made playful and self-reflective with a tiny model. - ๐Ÿ… **Off the Grid** โ€” fully local, zero external network requests, installable offline PWA. - ๐Ÿ… **Well-Tuned** โ€” custom distilled dataset + LoRA fine-tune of MiniCPM5-1B, healthy loss curve. - ๐Ÿ… **Sharing is Caring** โ€” open dataset, open training/distillation scripts, and a textbook-grade build log. - ๐Ÿ… **Field Notes** โ€” a detailed, honest construction log with the full bug chain. - ๐Ÿ† **OpenBMB** โ€” built on MiniCPM5-1B. - ๐Ÿ† **Modal** โ€” distillation/training pipeline ran on Modal A100. - ๐Ÿ† **Tiny Titan** โ€” a 1B model doing what you'd expect a 4B+ to do. ## How it meets the requirements | # | Requirement | How Tianwen meets it | |---|---|---| | REQ-01 | Under 32B | MiniCPM5-**1B** (and the rules fallback uses no model at all). | | REQ-02 | Gradio app on the org | Deployed as a Gradio Space (`app_file: app.py`) under `build-small-hackathon`. | | REQ-03 | Demo video | Linked at the top of this README. | | REQ-04 | Social post | Linked at the top of this README. | | REQ-05 | โ‰ค10 ZeroGPU apps | One app Space + one ZeroGPU model Space. | | REQ-06 | Tagged README | Track + badge tags in the frontmatter; write-up above. | ## Run locally ```bash # 1) Build the React frontend (the backend serves this build) cd frontend && pnpm install && pnpm build && cd .. # 2) Start the backend python app.py # โ†’ http://127.0.0.1:7860/ # 3) (optional) Serve the fine-tuned model for real LLM readings llama-server -m finetune/data/tianwen-minicpm1b-q4_k_m.gguf --port 8888 -c 4096 ``` Without a running LLM, Tianwen still works via the deterministic rules engine (Off the Grid). ## Repo map ``` app.py FastAPI + Gradio backend (serves frontend/dist, SSE streaming readings) bazi/ divination/ Deterministic charting & I-Ching engines (lunar-python) prompts/ System prompts, templates, OpenAI-compatible LLM client safety/ Crisis circuit-breaker + symbol re-mapping finetune/ Distillation (gen_distill.py) + Modal training (train_modal.py) + deploy frontend/ React + shadcn UI (build โ†’ frontend/dist) docs/FINETUNE_REPORT.md The build log (Field Notes) ``` ## License MIT. Charts via lunar-python (MIT); cities via GeoNames (CC BY 4.0). For reflection and entertainment only โ€” not a substitute for professional medical, psychological, or financial advice.