PROJECT TEMPLATE: Multi-Modal Application¶
Build applications with vision + language models.
Project Structure¶
multimodal-app/
โโโ README.md
โโโ pyproject.toml
โโโ uv.lock
โโโ config/
โ โโโ models_config.yaml
โ โโโ app_config.yaml
โโโ src/
โ โโโ __init__.py
โ โโโ models/
โ โ โโโ __init__.py
โ โ โโโ clip.py # CLIP model
โ โ โโโ blip.py # Image captioning
โ โ โโโ llava.py # LLaVA model
โ โ โโโ whisper.py # Speech-to-text
โ โโโ processors/
โ โ โโโ __init__.py
โ โ โโโ image.py # Image processing
โ โ โโโ audio.py # Audio processing
โ โ โโโ video.py # Video processing
โ โโโ embeddings/
โ โ โโโ __init__.py
โ โ โโโ image_embedder.py
โ โ โโโ text_embedder.py
โ โโโ retrieval/
โ โ โโโ __init__.py
โ โ โโโ image_search.py
โ โโโ generation/
โ โ โโโ __init__.py
โ โ โโโ captioning.py
โ โ โโโ vqa.py # Visual Q&A
โ โโโ api.py # FastAPI endpoints
โโโ data/
โ โโโ images/
โ โโโ audio/
โ โโโ videos/
โโโ frontend/
โ โโโ index.html
โ โโโ app.js
โ โโโ styles.css
โโโ tests/
โโโ test_multimodal.py
Features¶
- Image-text retrieval
- Image captioning
- Visual question answering
- Speech recognition
- Cross-modal search
Quick Start¶
Image-Text Retrieval¶
from src.models.clip import CLIPModel
from src.retrieval.image_search import ImageSearch
model = CLIPModel("openai/clip-vit-base-patch32")
search = ImageSearch(model, image_database="data/images")
# Text to image
results = search.search("a dog playing in the park", top_k=5)
# Image to text
results = search.search_by_image("query_image.jpg", top_k=5)
Image Captioning¶
from src.models.blip import BLIPCaptioner
captioner = BLIPCaptioner("Salesforce/blip-image-captioning-base")
caption = captioner.generate("image.jpg")
print(f"Caption: {caption}")
Visual Q&A¶
from src.models.llava import LLaVAModel
vqa = LLaVAModel("llava-hf/llava-1.5-7b-hf")
answer = vqa.answer(
image="image.jpg",
question="What color is the cat?"
)
print(f"Answer: {answer}")
Speech Recognition¶
from src.models.whisper import WhisperModel
whisper = WhisperModel("openai/whisper-base")
text = whisper.transcribe("audio.wav")
print(f"Transcript: {text}")
API Endpoints¶
# Image captioning
curl -X POST "http://localhost:8000/caption" \
-F "image=@image.jpg"
# Visual Q&A
curl -X POST "http://localhost:8000/vqa" \
-F "image=@image.jpg" \
-F "question=What is in this image?"
# Image search
curl -X POST "http://localhost:8000/search" \
-H "Content-Type: application/json" \
-d '{"query": "sunset on the beach"}'
Processing Pipeline¶
from src.processors.image import ImageProcessor
from src.processors.audio import AudioProcessor
# Image preprocessing
img_processor = ImageProcessor()
processed = img_processor.preprocess(
"image.jpg",
resize=(224, 224),
normalize=True
)
# Audio preprocessing
audio_processor = AudioProcessor()
processed = audio_processor.preprocess(
"audio.wav",
sample_rate=16000,
duration=30
)
Multi-Modal RAG¶
from src.generation.multimodal_rag import MultiModalRAG
rag = MultiModalRAG(
image_encoder="clip",
text_encoder="sentence-transformer",
generator="llava"
)
response = rag.query(
text_query="show me animals",
image_database="data/animals/"
)
Difficulty: โญโญโญ Advanced
Estimated Time: 10-15 hours
Skills: Multi-modal models, Computer vision, Audio processing