An AI-driven storytelling system that generates emotionally expressive stories from images or text using NLP, CNN, and TTS technologies.
See the codeMagicNarrate is an emotion-aware AI storytelling app that converts image or text prompts into children's stories, then narrates them with selectable voices.
src/: frontend appbackend/: local development backendhf-space/: Hugging Face Space backend sourcerunpod-worker/: RunPod serverless workerdocs/: documentation, architecture and model linksDocumentation:
cd backend
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
python server.py
Backend runs at http://localhost:8000.
cd ..
npm install
npm run dev
Frontend runs at http://localhost:5173.
backend/requirements.txt contains pinned versions for reproducible builds:
To verify your environment:
cd backend
source .venv/bin/activate
python server.py
# Should show: "Models loaded. Server ready."
Two Dockerfiles are provided:
HF Spaces (hf-space/Dockerfile):
docker build -f hf-space/Dockerfile -t magicnarrate-hf hf-space/
docker run -e OPENAI_API_KEY=your_key -p 7860:7860 magicnarrate-hf
RunPod Worker (runpod-worker/Dockerfile):
docker build -f runpod-worker/Dockerfile -t magicnarrate-runpod runpod-worker/
docker run -e OPENAI_API_KEY=your_key magicnarrate-runpod
Both use the same requirements.txt for consistency.
.env.local)VITE_API_URL=http://localhost:8000
VITE_AUDIO_JOB_POLL_INTERVAL_MS=2500
VITE_AUDIO_JOB_TIMEOUT_MS=420000
For production (Vercel):
VITE_API_URL=https://<your-space>.hf.space
backend/.env locally, HF Space Secrets in production)Copy backend/.env.example to backend/.env and set the values. Do not commit your .env file—it's already ignored by .gitignore.
TTS_PROVIDER modes:
local: generate audio in the backend process using Parler-TTS.runpod: create async RunPod jobs and poll until completion.Model source:
Runtime TTS model source:
Required files for backend/image_captioning/:
resnet50_attention_model.pthresnet50_features.ptvocab.ptRequired files for hf-space/image_captioning/:
resnet50_attention_model.pthvocab.ptQuick setup:
backend/image_captioning/ for local development.resnet50_attention_model.pth and vocab.pt into hf-space/image_captioning/ for Space deployment.vercel.json with Vite build output (dist).VITE_API_URL=https://<your-space>.hf.spaceVITE_AUDIO_JOB_POLL_INTERVAL_MS=2500VITE_AUDIO_JOB_TIMEOUT_MS=420000hf-space/.hf-space/Dockerfile (uvicorn on port 7860).OPENAI_API_KEYTTS_PROVIDER=runpodRUNPOD_API_KEYRUNPOD_ENDPOINT_IDAUDIO_JOB_POLL_INTERVAL_SEC=2.5AUDIO_JOB_TIMEOUT_SEC=420TTS_PROMPT_MAX_TOKENS=220Important note about this repository:
hf-space/ is currently ignored by .gitignore.hf-space/ will not be included unless you change ignore rules or use a separate repo/source for Space files.Create a queue-based serverless endpoint with:
/runpod-worker/Dockerfile/runpod-workerMagicNarrate-ttsRecommended starting settings:
0120-30 GBRun the verification script:
chmod +x verify-deployment.sh
./verify-deployment.sh https://<your-space>.hf.space https://<your-app>.vercel.app
Expected checks:
GET /health is healthyPOST /generate-audio-job returns job_idGET /: basic service informationGET /health: health checkGET /speakers: available speakersPOST /generate: generate story from imagePOST /generate-from-text: generate story from text promptPOST /generate-audio: synchronous local audio route (legacy/fallback)POST /generate-audio-job: create async audio jobGET /generate-audio-job/{job_id}: check async audio job statusDEPLOYMENT.mdDEPLOY_QUICK_START.mdDEPLOYMENT_CHECKLIST.mdAn AI-driven storytelling system that generates emotionally expressive stories from images or text using NLP, CNN, and TTS technologies.
See the codeMagicNarrate is an emotion-aware AI storytelling app that converts image or text prompts into children's stories, then narrates them with selectable voices.
src/: frontend appbackend/: local development backendhf-space/: Hugging Face Space backend sourcerunpod-worker/: RunPod serverless workerdocs/: documentation, architecture and model linksDocumentation:
cd backend
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
python server.py
Backend runs at http://localhost:8000.
cd ..
npm install
npm run dev
Frontend runs at http://localhost:5173.
backend/requirements.txt contains pinned versions for reproducible builds:
To verify your environment:
cd backend
source .venv/bin/activate
python server.py
# Should show: "Models loaded. Server ready."
Two Dockerfiles are provided:
HF Spaces (hf-space/Dockerfile):
docker build -f hf-space/Dockerfile -t magicnarrate-hf hf-space/
docker run -e OPENAI_API_KEY=your_key -p 7860:7860 magicnarrate-hf
RunPod Worker (runpod-worker/Dockerfile):
docker build -f runpod-worker/Dockerfile -t magicnarrate-runpod runpod-worker/
docker run -e OPENAI_API_KEY=your_key magicnarrate-runpod
Both use the same requirements.txt for consistency.
.env.local)VITE_API_URL=http://localhost:8000
VITE_AUDIO_JOB_POLL_INTERVAL_MS=2500
VITE_AUDIO_JOB_TIMEOUT_MS=420000
For production (Vercel):
VITE_API_URL=https://<your-space>.hf.space
backend/.env locally, HF Space Secrets in production)Copy backend/.env.example to backend/.env and set the values. Do not commit your .env file—it's already ignored by .gitignore.
TTS_PROVIDER modes:
local: generate audio in the backend process using Parler-TTS.runpod: create async RunPod jobs and poll until completion.Model source:
Runtime TTS model source:
Required files for backend/image_captioning/:
resnet50_attention_model.pthresnet50_features.ptvocab.ptRequired files for hf-space/image_captioning/:
resnet50_attention_model.pthvocab.ptQuick setup:
backend/image_captioning/ for local development.resnet50_attention_model.pth and vocab.pt into hf-space/image_captioning/ for Space deployment.vercel.json with Vite build output (dist).VITE_API_URL=https://<your-space>.hf.spaceVITE_AUDIO_JOB_POLL_INTERVAL_MS=2500VITE_AUDIO_JOB_TIMEOUT_MS=420000hf-space/.hf-space/Dockerfile (uvicorn on port 7860).OPENAI_API_KEYTTS_PROVIDER=runpodRUNPOD_API_KEYRUNPOD_ENDPOINT_IDAUDIO_JOB_POLL_INTERVAL_SEC=2.5AUDIO_JOB_TIMEOUT_SEC=420TTS_PROMPT_MAX_TOKENS=220Important note about this repository:
hf-space/ is currently ignored by .gitignore.hf-space/ will not be included unless you change ignore rules or use a separate repo/source for Space files.Create a queue-based serverless endpoint with:
/runpod-worker/Dockerfile/runpod-workerMagicNarrate-ttsRecommended starting settings:
0120-30 GBRun the verification script:
chmod +x verify-deployment.sh
./verify-deployment.sh https://<your-space>.hf.space https://<your-app>.vercel.app
Expected checks:
GET /health is healthyPOST /generate-audio-job returns job_idGET /: basic service informationGET /health: health checkGET /speakers: available speakersPOST /generate: generate story from imagePOST /generate-from-text: generate story from text promptPOST /generate-audio: synchronous local audio route (legacy/fallback)POST /generate-audio-job: create async audio jobGET /generate-audio-job/{job_id}: check async audio job statusDEPLOYMENT.mdDEPLOY_QUICK_START.mdDEPLOYMENT_CHECKLIST.md