How ainnov/draw-your-day works
Project type and purpose
• Purpose: Users write diary entries via a Streamlit frontend; the system uses a FastAPI backend, a PostgreSQL database, a QLoRA‑fine‑tuned LLaMA‑2 model for text understanding, and Stable Diffusion 1.5 for illustration generation.
File structure
• Top‑level files:
• app.py, main.py, server.py – entry points for Streamlit and FastAPI.
• create_tables.py – DB initialization.
• retrieval.py – likely the RAG retrieval logic.
• database/ – contains database.py (session/config) and models.py (ORM definitions).
• pages/ – Streamlit page modules (login, logout, diary_new, diary_list, cookie_manager).
• assets/ – images used in the README and web UI.
• template/ – prompt templates for RAG and full‑context queries.
• data/raw/ – raw JSON training data.
• data/ – example diaries used for local testing or evaluation.
README for additional insights
• Tech stack: FastAPI, StreamLit, PostgreSQL, QLoRA‑LLaMA2, Stable Diffusion.
• Two pipelines:
• Front/Backend pipeline (user ↔ frontend ↔ API ↔ DB & AI).
• AI pipeline (retrieval → LLaMA2 inference → Stable Diffusion).
Main components and their interactions
a. Frontend (Streamlit)
• pages/login, pages/logout handle auth state via cookies.
• pages/diary_new collects text input and submits it to the backend.
• pages/diary_list shows past entries and generated images.
• pages/cookie_manager manages session cookies.
b. Backend (FastAPI server.py / main.py)
• Exposes REST endpoints for login, logout, submit diary, list diaries.
• Orchestrates calls to the database layer and the AI pipeline.
c. Database (PostgreSQL via database/database.py & models.py)
• Stores user credentials, diary entries, and metadata (timestamps, image URLs).
• create_tables.py bootstraps the schema.
d. AI Pipeline
1. Retrieval (retrieval.py)
– Takes a new diary entry, queries Vector DB or JSON store (data/raw) for context.
2. LLaMA2 QLoRA inference
– Uses prompt templates (template/*.txt) to generate an image prompt.
3. Stable Diffusion 1.5
– Takes the generated prompt and renders an illustration (via a local pipeline, no external API).
e. Assets & Templates
– template/ holds the text‑to‑prompt templates for RAG and full context.
Architectural patterns and design principles
• Monolithic Python service but logically separated into frontend, API, DB, and AI sub‑modules.
• Clear separation of concerns: Streamlit handles UI, FastAPI handles business logic, database layer handles persistence, AI pipeline handles model inference.
• RAG pattern in retrieval.py, prompting pattern via template files, single‑host inference to minimize VRAM usage.
Detail and clarity
• Data flows end‑to‑end (user diary → DB & prompt → LLaMA2 → Stable Diffusion → image URL back to UI).
• Callouts for configuration (Streamlit config in .streamlit/config.toml, create_tables.py run step).