"""
ui/sonic.py
-----------
SONIC — the assistant caricature, drawn as an inline SVG (no external asset to
fetch, so it renders inside Gradio's HTML blocks with no network round-trip).
A friendly bespectacled researcher: brown quiff, black glasses, big smile,
white shirt + navy striped tie, suspenders. Used big on the welcome screen and
small as the chat avatar.
Two exports, for two different consumers:
SONIC_DATA_URI -> for inside gr.HTML markup
SONIC_AVATAR -> a real file on disk, because gr.Chatbot's avatar_images
takes a path/URL and will not accept a data: URI
"""
import base64
from ui.paths import ASSETS_DIR
SONIC_SVG = """
"""
SONIC_DATA_URI = "data:image/svg+xml;base64," + base64.b64encode(SONIC_SVG.encode("utf-8")).decode("ascii")
# gr.Chatbot(avatar_images=...) resolves paths/URLs only, so materialize the SVG.
SONIC_AVATAR = str(ASSETS_DIR / "sonic.svg")
(ASSETS_DIR / "sonic.svg").write_text(SONIC_SVG, encoding="utf-8")
USER_SVG = """
"""
USER_AVATAR = str(ASSETS_DIR / "user.svg")
(ASSETS_DIR / "user.svg").write_text(USER_SVG, encoding="utf-8")
def sonic_says(message: str) -> str:
"""SONIC's speech bubble. Returns markup for a gr.HTML block (the Streamlit
original wrote straight to the page; here the caller decides where it goes)."""
return (
f'