Spaces:
Running
Running
Skeleton: FastAPI + mounted Gradio barracks (Docker Space)
Browse filesServes a placeholder battle frontend at "/" and the barracks at "/app" with a
stub war-diary generator (wired to a local llama.cpp small model during the hack).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Dockerfile +21 -0
- README.md +27 -4
- app.py +64 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Tiny Army — HF Space (Docker SDK). FastAPI serves the custom frontend and mounts
|
| 2 |
+
# a Gradio app for the small-model barracks. llama.cpp gets added during the hack.
|
| 3 |
+
FROM python:3.11-slim
|
| 4 |
+
|
| 5 |
+
# HF Spaces run as a non-root user; keep caches writable.
|
| 6 |
+
ENV HOME=/home/user \
|
| 7 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 8 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 9 |
+
GRADIO_SERVER_PORT=7860
|
| 10 |
+
|
| 11 |
+
RUN useradd -m -u 1000 user
|
| 12 |
+
USER user
|
| 13 |
+
WORKDIR /home/user/app
|
| 14 |
+
|
| 15 |
+
COPY --chown=user requirements.txt .
|
| 16 |
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 17 |
+
|
| 18 |
+
COPY --chown=user . .
|
| 19 |
+
|
| 20 |
+
EXPOSE 7860
|
| 21 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,33 @@
|
|
| 1 |
---
|
| 2 |
title: Tiny Army
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Tiny Army
|
| 3 |
+
emoji: 🪖
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
short_description: Echo Wars — fighters write their own true legends
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# 🪖 Tiny Army
|
| 14 |
+
|
| 15 |
+
**HF Build Small Hackathon entry — Track 2 ("An Adventure in Thousand Token Wood").**
|
| 16 |
+
|
| 17 |
+
*Echo Wars: every fighter writes its own legend — and the legend is true.*
|
| 18 |
+
|
| 19 |
+
A small local LLM gives each auto-battler unit a persona and writes its first-person
|
| 20 |
+
war diary from what it actually lived through. The twist that makes the AI
|
| 21 |
+
**load-bearing**: a unit's experience-shaped "soul" *drives how it fights*, so the
|
| 22 |
+
diary describes the unit's own real, learned behaviour. Two small models, both
|
| 23 |
+
load-bearing — a 1–3B LLM for voice, a <1 MB policy net for tactics.
|
| 24 |
+
|
| 25 |
+
## Architecture
|
| 26 |
+
|
| 27 |
+
- **FastAPI** serves the custom Pixi battle frontend (the deterministic combat
|
| 28 |
+
engine + souls + the ONNX captain run in the browser).
|
| 29 |
+
- A **mounted Gradio app** (`/app`) is the barracks: persona + war-diary generation
|
| 30 |
+
via **llama.cpp** (local, no cloud — 🔌 Off the Grid + 🦙 Llama Champion).
|
| 31 |
+
|
| 32 |
+
This is the current skeleton; see the plan in the auto-battler repo
|
| 33 |
+
(`docs/design/hackathon-build-small.md`).
|
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tiny Army — HF Space skeleton.
|
| 2 |
+
|
| 3 |
+
FastAPI serves the (placeholder) Pixi battle frontend at "/", and a Gradio app —
|
| 4 |
+
the "barracks" — is mounted at "/app". For now the war-diary generator is a stub;
|
| 5 |
+
the hack wires it to a local llama.cpp small model. The combat engine + souls +
|
| 6 |
+
ONNX captain will run client-side in the frontend.
|
| 7 |
+
"""
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import uvicorn
|
| 10 |
+
from fastapi import FastAPI
|
| 11 |
+
from fastapi.responses import HTMLResponse
|
| 12 |
+
|
| 13 |
+
app = FastAPI(title="Tiny Army")
|
| 14 |
+
|
| 15 |
+
INDEX = """<!doctype html>
|
| 16 |
+
<html><head><meta charset="utf-8"><title>Tiny Army</title>
|
| 17 |
+
<style>
|
| 18 |
+
body{margin:0;height:100vh;display:grid;place-items:center;background:#0b0e12;
|
| 19 |
+
color:#f4ecd8;font-family:ui-monospace,Menlo,monospace;text-align:center}
|
| 20 |
+
.badge{font-size:64px} a{color:#ffd54a}
|
| 21 |
+
p{color:#9aa4b2;max-width:32rem;line-height:1.5}
|
| 22 |
+
</style></head>
|
| 23 |
+
<body><div>
|
| 24 |
+
<div class="badge">🪖</div>
|
| 25 |
+
<h1>Tiny Army</h1>
|
| 26 |
+
<p><em>Echo Wars: every fighter writes its own legend — and the legend is true.</em></p>
|
| 27 |
+
<p>The battlefield (Pixi) mounts here. For now, visit the barracks:
|
| 28 |
+
<a href="/app">/app</a></p>
|
| 29 |
+
</div></body></html>"""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@app.get("/", response_class=HTMLResponse)
|
| 33 |
+
def index():
|
| 34 |
+
return INDEX
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@app.get("/healthz")
|
| 38 |
+
def healthz():
|
| 39 |
+
return {"ok": True}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def write_diary(unit: str, traits: str) -> str:
|
| 43 |
+
"""Stub. Replaced during the hack by a local llama.cpp small model that writes
|
| 44 |
+
a first-person war diary from the unit's memory + traits."""
|
| 45 |
+
t = (traits or "").strip() or "untested"
|
| 46 |
+
return (f"— Diary of {unit or 'a nameless soldier'} ({t}) —\n\n"
|
| 47 |
+
f"(placeholder) Today I held the line. The small model will give me a "
|
| 48 |
+
f"real voice soon, shaped by what I lived through on the field.")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
with gr.Blocks(title="Tiny Army — Barracks", theme=gr.themes.Soft()) as barracks:
|
| 52 |
+
gr.Markdown("# 🪖 Tiny Army — Barracks\n"
|
| 53 |
+
"*Every fighter writes its own legend.* (skeleton — diary is a stub)")
|
| 54 |
+
with gr.Row():
|
| 55 |
+
unit = gr.Textbox(label="Unit", value="Bram the Warrior")
|
| 56 |
+
traits = gr.Textbox(label="Traits", value="Cautious, Veteran, Vengeful")
|
| 57 |
+
out = gr.Textbox(label="War diary", lines=6)
|
| 58 |
+
gr.Button("Write diary", variant="primary").click(write_diary, [unit, traits], out)
|
| 59 |
+
|
| 60 |
+
app = gr.mount_gradio_app(app, barracks, path="/app")
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.115.6
|
| 2 |
+
uvicorn==0.34.0
|
| 3 |
+
gradio==5.9.1
|