mod-higgsfield / app /characters.py
github-actions[bot]
Automated Deploy: 58555e752292dd34bbb1312f29d5942a18053eaa
9ec7973
Raw History Blame Contribute Delete
1.29 kB
"""Seeded characters: one directory each, holding the face photo and the voice sample."""
import json
from pathlib import Path
FILES = ('character.json', 'face.png', 'voice.wav', 'voice.txt')
class Characters:
def __init__(self, root):
self.items = {}
root = Path(root)
for directory in sorted(p for p in root.iterdir() if p.is_dir()) if root.is_dir() else []:
missing = [name for name in FILES if not (directory / name).is_file()]
if missing:
raise ValueError(f'Character {directory.name} is missing {", ".join(missing)}')
info = json.loads((directory / 'character.json').read_text())
self.items[directory.name] = {
'id': directory.name, 'name': info['name'],
# Describes the on-camera look and setting; conditions the talking-head model.
'appearance': info['appearance'],
'face': directory / 'face.png', 'voice': directory / 'voice.wav',
'voice_text': (directory / 'voice.txt').read_text().strip()}
def get(self, character_id):
return self.items.get(character_id)
def public(self):
return [{'id': c['id'], 'name': c['name'], 'appearance': c['appearance']} for c in self.items.values()]