Add cloud sprite providers and browser demos

This commit is contained in:
Emil
2026-07-29 13:54:36 +03:00
parent 703fef0f87
commit 0e8b5d1fbc
16 changed files with 1113 additions and 9 deletions
+64
View File
@@ -33,6 +33,17 @@ class DBStats:
avg_rating: float = 0.0
@dataclass
class StyleReference:
id: str
image_path: str
name: str
role: str
notes: Optional[str]
priority: int
created_at: str
class FeedbackDB:
"""SQLite-backed feedback database for generated sprites."""
@@ -55,6 +66,18 @@ class FeedbackDB:
""")
conn.execute("CREATE INDEX IF NOT EXISTS idx_prompt ON feedback(prompt)")
conn.execute("CREATE INDEX IF NOT EXISTS idx_rating ON feedback(rating)")
conn.execute("""
CREATE TABLE IF NOT EXISTS style_references (
id TEXT PRIMARY KEY,
image_path TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
role TEXT NOT NULL,
notes TEXT,
priority INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL
)
""")
conn.execute("CREATE INDEX IF NOT EXISTS idx_style_priority ON style_references(priority DESC)")
conn.commit()
return cls(conn)
@@ -154,6 +177,47 @@ class FeedbackDB:
self.conn.execute("DELETE FROM feedback WHERE id = ?", (entry_id,))
self.conn.commit()
def add_style_reference(
self,
image_path: str,
name: str,
role: str,
notes: Optional[str] = None,
priority: int = 0,
) -> str:
"""Register an existing image as a reusable visual style reference."""
existing = self.conn.execute(
"SELECT id FROM style_references WHERE image_path = ?", (image_path,)
).fetchone()
if existing:
self.conn.execute(
"UPDATE style_references SET name=?, role=?, notes=?, priority=? WHERE id=?",
(name, role, notes, priority, existing[0]),
)
self.conn.commit()
return existing[0]
reference_id = str(uuid.uuid4())
self.conn.execute(
"INSERT INTO style_references (id, image_path, name, role, notes, priority, created_at) "
"VALUES (?, ?, ?, ?, ?, ?, ?)",
(reference_id, image_path, name, role, notes, priority, str(int(time.time()))),
)
self.conn.commit()
return reference_id
def get_style_references(self, limit: int = 8) -> list[StyleReference]:
cursor = self.conn.execute(
"SELECT id, image_path, name, role, notes, priority, created_at "
"FROM style_references ORDER BY priority DESC, created_at DESC LIMIT ?",
(limit,),
)
return [StyleReference(*row) for row in cursor]
def delete_style_reference(self, reference_id: str) -> None:
self.conn.execute("DELETE FROM style_references WHERE id = ?", (reference_id,))
self.conn.commit()
def export_jsonl(self, path: str, min_rating: int = 4) -> int:
entries = self.top_rated(10000, min_rating)
lines = []