A React application demonstrating Chrome's built-in Prompt API with Gemini Nano. Features text chat, real-time camera recognition, audio transcription, interactive paint recognition, and yoga pose analysis modes.
- Text Chat Mode: Chat with Gemini Nano using streaming responses
- Camera Recognition Mode: Real-time image recognition with auto-capture
- Audio Transcription Mode: Real-time speech-to-text transcription
- Paint Recognition Mode: Draw on canvas and get AI to recognize your drawings
- Yoga Pose Analysis Mode: Real-time yoga pose detection and AI coaching using MediaPipe
- Multimodal Support: Send images along with text prompts
- Streaming Responses: See AI responses as they're generated with auto-scroll
- OS: Windows 10/11, macOS 13+ (Ventura), Linux, or ChromeOS (Chromebook Plus)
- Storage: At least 22GB free space
- Memory: 16GB RAM (for CPU inference) or GPU with 4GB+ VRAM
- Browser: Chrome 138 or later
You must enable the following flags in Chrome:
-
Open
chrome://flagsin your browser -
Enable these flags:
Flag Setting #optimization-guide-on-device-modelEnabled #prompt-api-for-gemini-nanoEnabled or Enabled multilingual #prompt-api-for-gemini-nano-multimodal-inputEnabled (for camera mode) -
Click Relaunch to restart Chrome
-
Verify the model status at
chrome://on-device-internals
npm installnpm run devOpen http://localhost:5173 in Chrome.
npm run build- Type your message in the text area
- Press Enter or click the send button
- Watch the streaming response appear
- Switch to the "Camera Recognition" tab
- Click "Start Camera" to enable your webcam
- Click "Start Auto Recognition" to begin continuous recognition
- The AI will describe what it sees every 5 seconds
- Click "Stop Auto Recognition" to pause
- Switch to the "Paint" tab
- Select a tool from the toolbar:
- Pen: Draw with the selected color and line width
- Eraser: Remove parts of your drawing
- Fill: Fill enclosed areas with the selected color
- Choose a color using the color picker
- Adjust the line width using the slider (1-50px)
- Draw on the canvas with your mouse or touch device
- After each stroke (mouse up/touch end), the AI automatically recognizes your drawing
- View AI responses in the right panel with Markdown formatting
- Use the "Clear" button to start over
- Switch to the "Yoga" tab
- Select a yoga pose from the dropdown:
- Downward-Facing Dog (ダウンドッグ)
- Warrior I (戦士のポーズ1)
- Warrior II (戦士のポーズ2)
- Tree Pose (木のポーズ)
- Triangle Pose (三角のポーズ)
- Click "Start Camera" to enable your webcam
- Position yourself so your full body is visible
- The right panel shows real-time analysis:
- Overall score (0-100)
- Individual joint angles with color-coded status
- Instant feedback on your form
- Click "Ask AI for Advice" for detailed coaching tips
- Use "Start Auto Analysis" for continuous AI feedback every 10 seconds
- React 19
- TypeScript
- Vite
- Tailwind CSS v4
- Lucide React (icons)
- React Markdown (for AI response rendering)
- MediaPipe Tasks Vision (for pose detection)
src/
├── components/
│ ├── Chat.tsx # Main chat component
│ ├── ChatMessage.tsx # Message display with Markdown rendering
│ ├── ChatInput.tsx # Input form with camera capture
│ ├── CameraView.tsx # Camera preview component
│ ├── AudioTranscription.tsx # Audio transcription component
│ ├── PaintCanvas.tsx # Interactive paint tool with AI recognition
│ ├── YogaMode.tsx # Yoga pose analysis main component
│ └── YogaPoseView.tsx # Camera + MediaPipe pose detection
├── hooks/
│ └── usePromptAPI.ts # Chrome Prompt API integration
├── utils/
│ └── yogaPoseAnalysis.ts # Pose analysis utilities and definitions
├── types/
│ └── prompt-api.d.ts # TypeScript definitions
├── App.tsx # Tab switching (Text, Camera, Audio, Paint, Yoga)
├── main.tsx
└── index.css # Tailwind CSS
const availability = await LanguageModel.availability();
// Returns: 'available' | 'downloadable' | 'no'const session = await LanguageModel.create({
systemPrompt: 'You are a helpful assistant.',
expectedInputLanguages: ['en', 'ja'],
expectedOutputLanguages: ['en'],
temperature: 0.7,
topK: 3,
});const stream = session.promptStreaming('Hello!');
for await (const chunk of stream) {
console.log(chunk);
}const session = await LanguageModel.create({
expectedInputs: [{ type: 'image' }],
expectedOutputLanguages: ['en'],
});
const response = await session.prompt([
{
role: 'user',
content: [
{ type: 'text', value: 'What is in this image?' },
{ type: 'image', value: canvasElement },
],
},
]);- Ensure you're using Chrome 138+
- Check that the required flags are enabled
- Restart Chrome after enabling flags
- Verify you have 22GB+ free storage
- Check
chrome://on-device-internalsfor errors - Ensure you have an unmetered network connection
- Allow camera permissions when prompted
- Enable
#prompt-api-for-gemini-nano-multimodal-inputflag
MIT





