build-small-hackathon/GenreGoblin
GenreGoblin
Plain text goes in. Theater comes out.
GenreGoblin turns everyday messages into copy-ready Shakespearean threats-without-threats, corporate apologies, anime speeches, haunted announcements, royal decrees, and more. It is a polished Gradio Space built for the Build Small Hackathon: Thousand Token Wood track.
Demo video: [add link] Social post: [add link]
Live Space: https://huggingface.co/spaces/build-small-hackathon/GenreGoblin
Trace dataset: https://huggingface.co/datasets/build-small-hackathon/genregoblin-traces
Modal health: https://krishnagaarg--genregoblin-minicpm-minicpmservice-health.modal.run
VoxCPM health: https://krishnagaarg--genregoblin-minicpm-voxcpmservice-health.modal.run
Official Hackathon References
- Build Small Hackathon event page
- Official Hugging Face organization
- Official registration and rules Space
- Official-organization 13-dimension quest dataset
- Official-organization sponsor prize notes
- OpenBMB MiniCPM3-4B model card
- OpenBMB VoxCPM2 model card
The official registration app lists three rules: models at or below 32B parameters, Gradio plus Hugging Face Spaces, and a demo video plus social post. Submissions are due June 15, 2026 at 23:59 UTC.
What It Does
- Enter an ordinary message.
- Choose one of 12 genres or write a custom persona.
- Set the use-case and theatrical intensity.
- Receive a stylized message, short version, Genre DNA, safety estimate, and agent trace.
- Continue with another message while preserving the same in-session voice.
The app includes six one-click demos, clipboard controls, instant browser speech, genre-designed VoxCPM2 voices, a share card, and a deterministic fallback so the text demo still works when inference does not.
Small-Model Native
The primary model is `openbmb/MiniCPM3-4B`, a compact 4B-parameter text model with strong instruction-following. GenreGoblin gives the model a compact structured task: preserve intent, apply a genre profile, score the result, and return JSON. The UI then validates and renders that structure.
No model over 4B parameters is part of the experience.
Inference Modes
GenreGoblin selects the first configured path and safely falls back if it fails:
- Hosted MiniCPM using
MINICPM_API_URL - Modal MiniCPM3-4B using
USE_MODAL=trueandMODAL_API_URL - Local Transformers using
ENABLE_LOCAL_MODEL=true - Deterministic demo engine with no credentials or model download
Copy .env.example to .env when configuring a backend. Secrets are never hardcoded.
Hosted endpoint
MINICPM_API_URL=https://your-endpoint.example/generate
MINICPM_API_KEY=your-secret
MINICPM_MODEL_ID=openbmb/MiniCPM3-4BHugging Face-style inputs endpoints work by default. For OpenAI-compatible endpoints, set MINICPM_API_FORMAT=openai or use a URL containing chat/completions.
Local MiniCPM
Local inference is deliberately opt-in because Torch and model weights make a Space heavier.
pip install -r requirements-local.txt
ENABLE_LOCAL_MODEL=true python app.pyModal
`modal_app.py` is the production GPU endpoint. The main app recovers to deterministic mode if Modal is unavailable, so an inference outage cannot break the demo.
The deployment runs MiniCPM3-4B on a Modal T4 and VoxCPM2 on a Modal L4, both with a persistent model cache. Their public health responses are linked near the top of this README.
pip install modal
modal setup
modal deploy modal_app.pySet the deployed endpoint URL:
USE_MODAL=true
MODAL_API_URL=https://your-workspace--genregoblin-minicpm-minicpmservice-generate.modal.run
VOXCPM_API_URL=https://your-workspace--genregoblin-minicpm-voxcpmservice-generate.modal.runGenre Voice Design
Every built-in genre has a distinct natural-language voice direction. The haunted railway uses a measured vintage announcer with unsettling pauses, while film noir uses a tired low narrator with dry sarcasm. VoxCPM2 receives the direction plus generated text and returns a 48 kHz WAV. No real person's voice is cloned.
Voice generation is user-triggered because VoxCPM2 is a diffusion TTS model. Warm generation takes roughly ten seconds in the deployed configuration; a fully cold container can take several minutes to load and compile. Instant preview remains available through browser speech while the studio voice is cold.
Run Locally
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python app.pyOn Windows PowerShell:
py -m venv .venv
.\.venv\Scripts\Activate.ps1
py -m pip install -r requirements.txt
py app.pyOpen http://localhost:7860. No API key is required for the fallback demo.
Run the offline smoke suite with:
python smoke_test.py
python quality_eval.pyquality_eval.py checks all 12 genres, 10 use cases, and five intensity levels: 600 combinations covering intent retention, genre vocabulary, forbidden words, channel length, short-version behavior, and output distinctness.
Deploy to Hugging Face Spaces
- Create a new Gradio Space.
- Push this repository to the Space.
- Optionally add
MINICPM_API_URL,MINICPM_API_KEY, or Modal values as Space secrets. - Keep no model secrets configured to run the instant deterministic demo.
The README frontmatter configures app.py as the Space entry point.
Agentic Experience
Each rewrite exposes an honest Goblin Agent Trace:
- Read plain intent
- Apply genre lens
- Preserve original meaning
- Adjust intensity
- Run a sendability check
- Add final polish
GoblinRewriteAgent runs an actual bounded agent loop: build a grounded draft plan, call the MiniCPM tool, parse its structured result, validate intent and safety, send one autonomous repair instruction when needed, then recover deterministically if the repair still fails. The generated Genre DNA stores vocabulary, rhythm, forbidden words, a signature phrase, and emotional temperature. Recent outputs are passed back as style memory during follow-ups.
Reliability and Safety
- Model output is requested as JSON and parsed defensively.
- Invalid JSON, network failures, and missing packages all recover to deterministic output.
- Unsafe requests are converted into non-threatening boundary-setting alternatives.
- User text is escaped before being placed in custom HTML.
- Sendability is a playful estimate, not a guarantee of appropriateness.
Official Quest Eligibility
Not claimed: Off the Grid (Modal is remote), Well-Tuned (no LoRA yet), Llama Champion (no llama.cpp runtime), Backyard AI (the primary track is whimsical), and Nemotron (no NVIDIA model in the current flow).
OpenAI Codex Sponsor Prize
GenreGoblin also targets Best Use of Codex, a sponsor prize separate from the official 13-dimension quest classifier. The official-organization sponsor notes define the requirement as Codex-attributed commits in the connected GitHub repository or Space.
Codex implemented and tested the rewrite agent, genre quality system, VoxCPM2 integration, Modal deployment, UI refinement, evaluation scripts, and submission documentation. Final Space commits include the standard Co-authored-by: Codex <codex@openai.com> trailer.
Demo Script
- Click I'm running late to reveal the haunted railway announcement.
- Point out the sendability and chaos meters.
- Open Behind the rewrite, then briefly show the agent trace.
- Enter
Please bring snacks toounder Continue in the same voice. - Use Instant preview, then Generate genre voice to compare browser and VoxCPM2 speech.
- Open the share card and copy its social text.
- Switch to Anime Power-Up Speech, intensity 5, for the finale.
- Mention MiniCPM3-4B + VoxCPM2 on Modal, all models at or below 4B, and deterministic recovery.
Structure
app.py Gradio UI, model adapters, fallback engine, state, rendering
modal_app.py Production Modal text and VoxCPM2 voice endpoints
smoke_test.py Offline checks for genres, safety, JSON, and continuity
evaluate.py Reproducible seven-case product evaluation
quality_eval.py 600-case genre/use-case/intensity quality matrix
FIELD_NOTES.md Build journal and small-model lessons
SUBMISSION.md Final links, prize claims, and demo checklist
SOCIAL_POST.md Ready-to-publish social post draft
data/ Synthetic privacy-safe agent trace examples
requirements.txt Lightweight default Space dependencies
requirements-local.txt Optional Transformers/Torch dependencies
.env.example Backend configuration templateCodex Attribution
OpenAI Codex was used for implementation, prompt design, deterministic genre writing, custom Gradio UI polish, safety/recovery behavior, and local evaluation scripts/checks.
License
MIT
