🎯 Mục tiêu bài học
Xây dựng Image Processing Platform kết hợp tất cả kỹ thuật đã học: generation, editing, analysis, và multimodal pipelines.
Sau bài này, bạn sẽ:
✅ Xây dựng Image Processing Platform hoàn chỉnh ✅ Thiết kế RESTful API cho image generation, editing, analysis ✅ Implement testing strategy cho multimodal applications ✅ Tổng kết toàn bộ kiến thức Image & Multimodal AI
🔍 Project Overview
Project Structure
1image-platform/2 app/3 main.py4 generators.py5 editors.py6 analyzers.py7 models.py8 tests/9 static/10 uploads/11 outputs/12 requirements.txtCheckpoint
Bạn đã hiểu kiến trúc tổng quan và cấu trúc project chưa?
📐 Models
1# app/models.py2from pydantic import BaseModel, Field3from typing import List, Optional, Literal45class GenerateRequest(BaseModel):6 prompt: str7 style: Literal["photo", "illustration", "art", "3d"] = "photo"8 size: Literal["1024x1024", "1792x1024", "1024x1792"] = "1024x1024"9 provider: Literal["dalle", "sd"] = "dalle"1011class AnalyzeRequest(BaseModel):12 image_url: str13 tasks: List[Literal["describe", "classify", "tag", "ocr", "quality"]]1415class AnalyzeResponse(BaseModel):16 description: Optional[str] = None17 classification: Optional[dict] = None18 tags: Optional[List[str]] = None19 text_content: Optional[str] = None20 quality_score: Optional[int] = None2122class EditRequest(BaseModel):23 image_url: str24 operation: Literal["remove_bg", "upscale", "style_transfer"]25 style_reference: Optional[str] = NoneCheckpoint
Bạn đã thiết kế Pydantic models cho API requests và responses chưa?
🎨 Generators
1# app/generators.py2from openai import OpenAI34client = OpenAI()56style_map = {7 "photo": "professional photography, realistic, high quality, 8K",8 "illustration": "digital illustration, clean lines, vibrant colors",9 "art": "fine art painting, artistic, expressive brushstrokes",10 "3d": "3D render, octane render, volumetric lighting, detailed"11}1213async def generate_dalle(prompt: str, style: str, size: str):14 full_prompt = f"{prompt}, {style_map.get(style, '')}"15 16 response = client.images.generate(17 model="dall-e-3",18 prompt=full_prompt,19 size=size,20 quality="hd"21 )22 23 return {24 "url": response.data[0].url,25 "revised_prompt": response.data[0].revised_prompt26 }Checkpoint
Bạn đã implement image generator module với style mapping chưa?
🔍 Analyzers
1# app/analyzers.py2from langchain_openai import ChatOpenAI3from langchain_core.messages import HumanMessage45llm = ChatOpenAI(model="gpt-4o")67async def analyze_image(image_url: str, tasks: list):8 results = {}9 10 for task in tasks:11 prompts = {12 "describe": "Mo ta chi tiet hinh anh nay.",13 "classify": "Classify hinh anh nay vao category phu hop.",14 "tag": "Generate 10 tags cho hinh anh nay.",15 "ocr": "Extract tat ca text trong hinh anh.",16 "quality": "Danh gia chat luong anh 1-10 va giai thich."17 }18 19 response = await llm.ainvoke([20 HumanMessage(content=[21 {"type": "text", "text": prompts[task]},22 {"type": "image_url", "image_url": {"url": image_url}}23 ])24 ])25 results[task] = response.content26 27 return resultsCheckpoint
Bạn đã implement analyzer module với multi-task support chưa?
💻 FastAPI Backend
1# app/main.py2from fastapi import FastAPI, UploadFile, File3from fastapi.staticfiles import StaticFiles4from app.models import *5from app.generators import generate_dalle6from app.analyzers import analyze_image78app = FastAPI(title="Image Processing Platform")9app.mount("/static", StaticFiles(directory="static"), name="static")1011@app.post("/generate")12async def generate(request: GenerateRequest):13 result = await generate_dalle(request.prompt, request.style, request.size)14 return result1516@app.post("/analyze")17async def analyze(request: AnalyzeRequest):18 results = await analyze_image(request.image_url, request.tasks)19 return results2021@app.post("/upload")22async def upload(file: UploadFile = File(...)):23 content = await file.read()24 path = f"static/uploads/{file.filename}"25 with open(path, "wb") as f:26 f.write(content)27 return {"url": f"/static/uploads/{file.filename}"}Checkpoint
Bạn đã thiết kế và implement các API endpoints cho platform chưa?
🧪 Testing
1# tests/test_platform.py2import pytest3from httpx import AsyncClient4from app.main import app56@pytest.mark.asyncio7async def test_generate():8 async with AsyncClient(app=app, base_url="http://test") as ac:9 response = await ac.post("/generate", json={10 "prompt": "A beautiful sunset",11 "style": "photo",12 "size": "1024x1024"13 })14 assert response.status_code == 20015 assert "url" in response.json()Rubric đánh giá
| Criteria | Points |
|---|---|
| Image Generation (DALL-E) | 20 |
| Image Analysis (Vision) | 20 |
| Image Editing | 15 |
| Multimodal Pipeline | 15 |
| API Design | 10 |
| Error Handling | 10 |
| Testing | 5 |
| Code Quality | 5 |
| Total | 100 |
Checkpoint
Bạn đã viết test cases và hiểu rubric đánh giá cho capstone project chưa?
🎯 Tổng kết
Key Takeaways
- Image Generation: DALL-E 3, Stable Diffusion, ComfyUI
- Prompt Engineering: Style, composition, quality keywords
- Image Editing: Inpainting, outpainting, background removal
- ControlNet: Canny, depth, pose control
- Vision Models: GPT-4V, Claude Vision, structured extraction
- Multimodal: Kết hợp text + image pipelines
- Production: API design, batch processing, cost management
Câu hỏi tự kiểm tra
- Các module chính của Image Processing Platform gồm những gì và chúng tương tác với nhau như thế nào?
- Làm sao thiết kế RESTful API cho image generation, editing và analysis trong một platform thống nhất?
- Testing strategy cho multimodal applications (image + text) cần chú ý những điểm đặc biệt gì?
- Làm sao quản lý chi phí và tối ưu hiệu suất khi deploy image processing platform lên production?
🎉 Tuyệt vời! Bạn đã hoàn thành toàn bộ khóa học Image & Multimodal AI!
Bạn đã thành thạo: Image Generation (DALL-E 3, Stable Diffusion), Prompt Engineering, Image Editing, ControlNet, Vision Models, Image Analysis, Visual QA, và Multimodal Pipelines. Hãy áp dụng những kỹ năng này vào các dự án thực tế!
Chúc mừng bạn đã hoàn thành khóa học Image Processing với AI! 🎉
Tiếp theo: GenAI Deployment →
