How maihuuthien/totem works
1. Overall shape
- This repo is a single-user “proxy chatbot” application with one main runtime entrypoint, app.py.
- The app serves a Gradio UI, answers questions about the owner, and can optionally turn the last answer into a talking-avatar playback.
2. Interactive front end
- The user-facing boundary is the Gradio app.
- It exposes a chat experience plus secondary actions like “play the last answer,” so the UI is not just text chat; it also triggers media generation/playback.
3. Conversation / answer generation layer
- The core chat logic lives in app.py and is driven by a system prompt built from personal source material.
- It can use either OpenAI-hosted models or a local Ollama model, which creates a clear split between cloud inference and local inference modes.
4. Personal knowledge ingestion
- The app reads the me/ folder as its knowledge base:
- me/linkedin.pdf for structured career history
- me/summary.txt for a short personal narrative
- These files feed the prompt/context construction used to answer questions as if the chatbot were the owner.
5. Unknown-question and lead-capture workflow
- The README describes two side-channel actions beyond answering:
- collecting visitor contact information
- logging questions it could not answer
- These are treated as application-level events, separate from the model response path, and can be used for follow-up or future prompt improvements.
6. Notification boundary
- Optional Pushover integration sends real-time notifications for new contacts and unknown questions.
- This is an outbound integration layer, not part of the core conversational path, and is only active when configured via environment variables.
7. Talking-avatar media pipeline
- The avatar/speaking feature is backed by the vendored LatentSync/ package.
- That package contains the lip-sync inference stack: model definitions, pipeline orchestration, utilities, and config files for syncnet/unet stages.
- This subsystem is effectively isolated as a media-generation engine used after the text answer is produced.
8. Audio feature extraction
- Inside LatentSync/latentsync/whisper/ is a bundled Whisper-based transcription/audio-feature implementation.
- audio2feature.py and the embedded Whisper code turn audio into features that can be consumed by the lip-sync pipeline.
- This indicates a pre-processing step between audio/text generation and synchronized video output.
9. Model/config separation
- The LatentSync/configs/ directory holds the architecture and stage configs for the sync pipeline:
- syncnet variants for latent/pixel modes
- unet first/second stage configs
- audio and scheduler settings
- This implies the media subsystem is heavily configuration-driven, with inference behavior decoupled from application code.
10. Inference entrypoint for lip-sync
- LatentSync/scripts/inference.py is the dedicated inference driver for the avatar pipeline.
- The main app likely invokes this subsystem when the user requests playback of the last answer, using me/ref_video.mp4 as the source face video and a synthesized voice track as input.
11. Reference assets and personalization
- The me/ directory also contains ref_audio.mp3, ref_video.mp4, and summary.txt, which are user-specific assets.
- These files are part of the application data, not generic library code, and are required to make the chatbot visually and vocally personalized.
12. Deployment/runtime boundary
- The repo is designed to run in two environments:
- local development with Python 3.10 and optionally Ollama
- HuggingFace Spaces deployment with OpenAI-backed inference
- Dockerfile, requirements.txt, and pyproject.toml support containerized and reproducible execution, while the Gradio SDK metadata in the README identifies the app as a Space-style deployment.
13. Important architectural split to show in a diagram
- One branch is the conversational stack: Gradio UI → prompt/context assembly → LLM backend → response.
- The second branch is the media stack: response text → TTS/audio assets → Whisper/audio feature extraction → LatentSync lip-sync inference → avatar playback.
- Side integrations branch off from the app logic to Pushover and contact logging.
14. What is intentionally vendored
- LatentSync/ includes substantial third-party-style code and assets rather than depending on it as a remote service.
- That means the repository is self-contained for the avatar pipeline, while the LLM remains external or locally hosted depending on configuration.
Main entry points: app.py App · lipsync_pipeline.py Pipeline Core · inference.py Lip-sync Inference · ref_audio.mp3 Voice Track
Components 21
Application
Main chatbot runtime and outbound integrations.
- App · Main entrypoint serving the chatbot and orchestration logic.
app.py - Chat UI · User-facing chat interface and playback controls.
- Prompt Builder · Builds the system prompt and conversation context from personal source material.
- LLM Router · Chooses between hosted OpenAI models and local Ollama inference.
- OpenAI · External hosted inference path.
- Ollama · Local model inference path.
- Answer Flow · Produces the owner-style answer returned to the user.
- Contact Capture · Collects visitor contact information for follow-up.
- Unknown Questions · Records questions the bot could not answer.
- Pushover · Optional realtime notifications for new contacts and unknown questions.
- Playback Trigger · Starts the last-answer speaking/avatar playback path.
Personal Data
User-specific source material used to personalize answers.
- Personal KB · Owner-specific knowledge base used to answer as the user.
- Career PDF · Structured career history source.
me/linkedin.pdf - Summary · Short personal narrative used for grounding.
me/summary.txt
Avatar Media
Audio/video generation path for speaking playback.
- Voice Track · Audio used as the spoken version of the last answer.
me/ref_audio.mp3 - Ref Video · Reference face video used for personalized playback.
me/ref_video.mp4 - Audio Features · Extracts audio features for lip-sync conditioning.
LatentSync/latentsync/whisper/audio2feature.py
LatentSync
Vendored lip-sync inference stack.
- Lip-sync Inference · Runs the talking-avatar inference pipeline.
LatentSync/scripts/inference.py - Pipeline Core · Orchestrates avatar synthesis and frame generation.
LatentSync/latentsync/pipelines/lipsync_pipeline.py - Model Stages · SyncNet and U-Net stages plus supporting model blocks.
LatentSync/latentsync/models/unet.py - Configs · Architecture and scheduler configuration for the vendored media stack.
LatentSync/configs
Connections 23
- Chat UI → App: chat / actions · UI sends user messages and control actions to the runtime.
- App → Prompt Builder: build context · Creates the system prompt and conversation context.
- Prompt Builder → Personal KB: reads · Uses personal source material for grounding.
- Personal KB → Career PDF: includes · Structured career history.
- Personal KB → Summary: includes · Short personal narrative.
- Prompt Builder → LLM Router: send prompt · Hands the assembled prompt to the model selector.
- LLM Router → OpenAI: cloud mode · Routes to hosted inference when configured.
- LLM Router → Ollama: local mode · Routes to local model inference when configured.
- OpenAI → Answer Flow: return text · Produces the chat answer.
- Ollama → Answer Flow: return text · Produces the chat answer.
- App → Contact Capture: capture contact · Records visitor contact details as an application event.
- App → Unknown Questions: log miss · Records unanswered questions as an application event.
- Contact Capture → Pushover: notify · Optional notification for new contacts.
- Unknown Questions → Pushover: notify · Optional notification for unknown questions.
- Answer Flow → Playback Trigger: play last answer · Triggers the speaking-avatar branch after response generation.
- Playback Trigger → Voice Track: use voice · Uses the synthesized or prepared voice track.
- Playback Trigger → Ref Video: use face video · Uses the reference avatar video asset.
- Voice Track → Audio Features: extract features · Converts audio into conditioning features.
- Audio Features → Lip-sync Inference: condition · Feeds lip-sync inference.
- Ref Video → Lip-sync Inference: reference input · Provides the source face video.
- Lip-sync Inference → Pipeline Core: orchestrate · Runs the core synthesis pipeline.
- Pipeline Core → Model Stages: use models · Applies the vendored model stack.
- Pipeline Core → Configs: load config · Uses stage and scheduler configuration.