Drop a book cover here
or click to browse
or click to browse
01
Upload a photo of any book cover. BookLens will identify the title, author, and pull metadata from Google Books.
Analysing cover image…
Extracting title & author…
Fetching from Google Books…
Compiling result…
Book identified
HIGH MATCH
Deploy to Cloudflare Workers
This demo uses the Claude API to simulate vision. To use Cloudflare Workers AI (Llama 3.2-Vision) in production, deploy this Worker. Your frontend then calls https://your-worker.workers.dev/scan instead.
// Cloudflare Worker — BookLens backend
// Deploy: wrangler deploy
export default {
async fetch(request, env) {
const headers = {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
};
if (request.method === 'OPTIONS')
return new Response(null, { headers });
if (request.method !== 'POST')
return new Response('Method not allowed', { status: 405 });
try {
// 1. Receive image as base64 from frontend
const { imageBase64 } = await request.json();
// 2. Run Llama 3.2-Vision on Cloudflare Workers AI
const aiResponse = await env.AI.run('@cf/meta/llama-3.2-11b-vision-instruct', {
messages: [{
role: 'user',
content: [
{ type: 'text', text: 'This is a book cover. Extract the exact book title and author name. Reply in JSON: {"title":"...","author":"..."}' },
{ type: 'image_url', image_url: { url: `data:image/jpeg;base64,${imageBase64}` } }
]
}],
max_tokens: 150,
});
// 3. Parse the AI response
const parsed = JSON.parse(aiResponse.response);
const { title, author } = parsed;
// 4. Lookup on Google Books API (free)
const query = encodeURIComponent(`${title} ${author}`);
const booksRes = await fetch(
`https://www.googleapis.com/books/v1/volumes?q=${query}&maxResults=1&key=${env.GOOGLE_BOOKS_API_KEY}`
);
const booksData = await booksRes.json();
const book = booksData.items?.[0]?.volumeInfo || {};
// 5. Return merged result
return new Response(JSON.stringify({
title: book.title || title,
author: (book.authors || [author]).join(', '),
publisher: book.publisher,
publishedDate: book.publishedDate,
pageCount: book.pageCount,
categories: book.categories?.[0],
description: book.description,
infoLink: book.infoLink,
}), { headers });
} catch (err) {
return new Response(JSON.stringify({ error: err.message }), { status: 500, headers });
}
}
};
name = "booklens-worker"
main = "worker.js"
compatibility_date = "2024-01-01"
[ai]
binding = "AI"
[vars]
GOOGLE_BOOKS_API_KEY = "YOUR_API_KEY_HERE"
1
Install Wrangler CLI:
npm install -g wrangler then wrangler login2
Get a free Google Books API key from
console.cloud.google.com and add it to wrangler.toml3
Deploy:
wrangler deploy — your Worker URL will be shown. Update WORKER_URL in index.html4
Enable Workers AI in your Cloudflare dashboard (free tier: 10,000 neurons/day)