Skip to content

venkatarangan/PromptAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI in Your Browser - Chrome Prompt API Demos

Chrome Gemini Nano License

Bringing AI directly into your browser - no servers, no subscriptions, complete privacy.

This project explores Google Chrome's experimental Prompt API, which brings small AI models directly into the browser. With Gemini Nano running locally on your device, you can perform AI tasks without sending data to external servers, paying subscription fees, or worrying about privacy concerns.

๐ŸŽฏ What This Project Does

This repository contains three interactive demos showcasing the capabilities of on-device AI in Chrome:

1๏ธโƒฃ AI Creative Writing Assistant (app.html)

Feed it a theme, mood, and desired length, and watch as it generates:

  • ๐Ÿ“ Poems - Creative verses on any topic
  • ๐Ÿ“– Short Stories - Narrative fiction with your chosen mood
  • ๐Ÿ’ฌ Dialogues - Conversational exchanges between characters
  • โœจ Custom Content - Any creative writing you can imagine

Prompt API

2๏ธโƒฃ AI Translation Assistant (translate.html)

Instant translation between multiple languages, all running locally:

  • ๐ŸŒ Supports 12+ languages (English, Spanish, French, German, Japanese, Chinese, and more)
  • โšก Real-time translation without cloud API calls
  • ๐Ÿ”’ Complete privacy - text never leaves your device
  • ๐Ÿ†“ No translation API costs

3๏ธโƒฃ AI Vision Assistant (image.html)

Upload an image and let the browser's AI describe what it sees:

  • ๐Ÿ–ผ๏ธ Image analysis and description
  • ๐ŸŽจ Visual content understanding
  • ๐Ÿ“ท Object and scene recognition
  • ๐Ÿ’ป All processing happens locally on your PC

๐Ÿค” Why This Matters

Traditional AI applications require:

  • โ˜๏ธ Cloud infrastructure and server costs
  • ๐Ÿ’ณ Subscription fees or per-use API charges
  • ๐Ÿ”“ Sending your data to external servers
  • ๐Ÿ“ถ Constant internet connectivity
  • โฑ๏ธ Network latency for every request

On-device AI changes this:

  • โœ… Runs directly in your browser
  • โœ… Zero server costs
  • โœ… Complete data privacy
  • โœ… Works offline (after initial model download)
  • โœ… Instant responses with no network latency
  • โœ… Perfect for browser extensions and web apps

๐Ÿš€ How to Run

Prerequisites

  1. Google Chrome v128 or later (as of July 2025)

  2. Enable Experimental Flags

    Navigate to these Chrome flags and enable them:

    chrome://flags/#prompt-api-for-gemini-nano
    chrome://flags/#prompt-api-for-gemini-nano-multimodal-input
    chrome://flags/#optimization-guide-on-device-model
    

    After enabling, restart Chrome.

  3. First Run Model Download

    • The first time you use the API, Chrome will download Gemini Nano (~1-2GB)
    • This is a one-time download
    • Subsequent uses will be instant

Running the Demos

Option 1: Simple HTTP Server (Python)

# Navigate to the project folder
cd c:\DevTemp\promptai

# Start a local web server
python -m http.server 8000

Then open your browser:

Option 2: Direct File Access

You can also open the HTML files directly in Chrome:

  • Right-click on any .html file โ†’ "Open with" โ†’ Google Chrome

๐Ÿ› ๏ธ How It Works

The Technology Stack

  • Chrome Prompt API - Browser-native AI interface
  • Gemini Nano - Google's compact on-device AI model
  • Vanilla JavaScript - No frameworks, pure web standards
  • HTML5 & CSS3 - Modern, responsive interfaces

Behind the Scenes

  1. Availability Check

    const availability = await LanguageModel.availability();
  2. Session Creation

    const session = await LanguageModel.create({
      topK: params.defaultTopK,
      temperature: params.defaultTemperature
    });
  3. Prompt Execution

    const response = await session.prompt(userInput);
  4. Multimodal Input (for image analysis)

    const session = await LanguageModel.create({
      multimodal: true
    });
    const response = await session.prompt([text, imageBlob]);

Key Features

  • Download Progress Monitoring - Track model download status
  • Session Management - Efficient resource handling
  • Error Handling - Graceful fallbacks for unsupported systems
  • Responsive UI - Works on desktop and tablet devices
  • Real-time Generation - Instant AI responses

๐Ÿ“ Project Structure

promptai/
โ”‚
โ”œโ”€โ”€ app.html                    # Creative Writing Assistant
โ”œโ”€โ”€ translate.html              # Translation Assistant  
โ”œโ”€โ”€ image.html                  # Vision/Image Analysis
โ”œโ”€โ”€ PromptAPISample.html        # Basic API test demo
โ”œโ”€โ”€ code.html                   # Demo screenshots gallery
โ”‚
โ”œโ”€โ”€ images/                     # Screenshots and assets
โ”‚   โ”œโ”€โ”€ 1.png                   # Creative writing demo
โ”‚   โ”œโ”€โ”€ 2.png                   # Translation demo
โ”‚   โ”œโ”€โ”€ 3.png                   # Image analysis demo
โ”‚   โ””โ”€โ”€ joke-visual.png         # Sample test image
โ”‚
โ””โ”€โ”€ cgi-bin/                    # Web server utilities
    โ”œโ”€โ”€ web.py                  # Simple Python CGI script
    โ””โ”€โ”€ web.md                  # Server instructions

๐ŸŒŸ Features by Demo

Creative Writing Assistant

  • 4 content types (poem, story, dialogue, custom)
  • Mood selection (happy, sad, mysterious, humorous, etc.)
  • Length control (short, medium, long)
  • Theme-based generation
  • Beautiful gradient UI with animations

Translation Assistant

  • 12+ language support
  • Bidirectional translation
  • Swap source/target languages
  • Real-time translation
  • Clean, intuitive interface
  • Character count display

Image Description Assistant

  • Drag-and-drop image upload
  • File browser support
  • Detailed image analysis
  • Custom prompt support
  • Example prompts included
  • Sample images for testing

๐Ÿ”ฎ Future Possibilities

This is just the beginning. The Prompt API opens doors to:

  • ๐Ÿ”Œ Browser Extensions - AI-powered tools without backend infrastructure
  • ๐Ÿ“ Content Tools - Writing assistants, grammar checkers, summarizers
  • ๐ŸŽจ Creative Apps - Story generators, code helpers, brainstorming tools
  • ๐Ÿ”’ Privacy-First Apps - Sensitive data processing without cloud exposure
  • ๐ŸŒ Offline-First Apps - AI that works without internet
  • ๐Ÿ“Š Data Analysis - Local processing of sensitive information

โš ๏ธ Current Limitations

  • Model Size - Gemini Nano is compact; complex tasks may need larger models like ChatGPT or Claude
  • Browser Support - Currently Chrome 128+ only (Edge Canary has experimental support)
  • Experimental Status - API may change before stable release
  • Hardware Requirements - Works best with modern CPUs and GPUs
  • Initial Download - ~1-2GB model download on first use

๐ŸŒ Browser Support

Browser Status Model
Chrome 128+ โœ… Available (experimental) Gemini Nano
Edge Canary ๐Ÿงช Testing Phi-4
Firefox โŒ Not yet -
Safari โŒ Not yet -

๐Ÿ“š References & Resources

๐Ÿค Contributing

Feel free to:

  • ๐Ÿ› Report bugs or issues
  • ๐Ÿ’ก Suggest new demo ideas
  • ๐Ÿ”ง Submit pull requests
  • ๐Ÿ“– Improve documentation
  • ๐ŸŒŸ Share your experience with the Prompt API

๐Ÿ“ Development Notes

The HTML, CSS, and JavaScript for these demos were generated with assistance from Claude AI, following the official Prompt API documentation from the Web Machine Learning Community Group.

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ‘ค Author

Created as an exploration of Chrome's experimental Prompt API and on-device AI capabilities.

Blog Post: AI is now inside your browser โ€“ Prompt API
Date: July 17, 2025

๐Ÿ’ฌ Feedback

I'd love to hear about your experience with these demos! If you try them out, please share:

  • What worked well
  • What could be improved
  • Ideas for new demos
  • Your thoughts on on-device AI

โญ If you find this project interesting, please star it on GitHub!

Built with curiosity, powered by on-device AI ๐Ÿš€

About

Using local AI inside your browser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors