Transforming Online Shopping with On-Device Intelligence
🎯 The Challenge: When Convenience Meets Uncertainty
Imagine ordering your perfect outfit online, only to find it doesn't fit when it arrives. You're not alone – this scenario plays out millions of times daily, creating a cascade of problems:
The Numbers Tell a Story
- 💰 $218 billion in annual returns (National Retail Federation)
- 📦 30-40% of online clothing purchases returned
- 🌍 16 million metric tons of CO2 from return shipping
- 💸 Retailers lose $33 for every $50 return
- 😞 72% of shoppers cite sizing as their primary concern
Why This Matters

🤔 Why Not Just Compare Measurements?
The seemingly simple solution of comparing numbers falls short because clothing fit is surprisingly complex:
- Material Variations: A size M in stretch denim fits differently than in rigid cotton
- Brand Inconsistency: No standardization across brands
- Body Dynamics: Static measurements don't capture body shape nuances
- Personal Preferences: "Fitted" means different things to different people
💡 Our Innovation: Making AI Personal and Private
SmartFit Chrome Extension leverages Google's Gemini Nano for on-device AI analysis, transforming how we approach size recommendations. Here's why this is revolutionary:

The Power of On-Device LLMs
class AIService {
async initialize() {
try {
if (this.initialized) return true;
console.log("Initializing AI service...");
const capabilities = await ai.languageModel.capabilities();
console.log("AI capabilities:", capabilities);
if (capabilities.available === 'no') {
throw new Error('Language model not available');
}
const systemPrompt = `You are a clothing size recommendation expert. Your task is to analyze measurements and provide accurate size recommendations.
Rules:
1. Always respond in English
2. Use exact measurements in centimeters
3. Consider both user measurements and garment measurements
4. Account for fabric stretch and fit preferences
5. Be precise with numbers and calculations
Analyze the measurements provided and respond EXACTLY in this format:
MEASUREMENTS ANALYSIS:
[Compare user measurements with size chart measurements]
BEST SIZE: [Recommend specific size]
CONFIDENCE: [high/medium/low]
REASONING: [Brief explanation with numbers]
FIT TYPE: [fitted/regular/loose]
KEY MEASUREMENTS:
[List key differences]
POTENTIAL ISSUES:
[List potential fit problems]
ALTERNATIVE SIZES:
[List alternatives with reasons]`;
this.session = await ai.languageModel.create({
systemPrompt,
temperature: 0.3, // Lower temperature for more consistent output
topK: 1, // Most likely token only
maxOutputTokens: 750,
safetySettings: [
{
category: "HARM_CATEGORY_DEROGATORY",
threshold: "BLOCK_LOW_AND_ABOVE"
}
]
});
this.initialized = true;
console.log("AI service initialized successfully");
return true;
} catch (error) {
console.error("Failed to initialize AI:", error);
this.initialized = false;
throw error;
}
}
createAnalysisPrompt(productData, sizeChart, measurements, userProfile) {
let prompt = `Analyze these measurements for ${productData.title || 'this garment'}:
PRODUCT DETAILS:
- Category: ${productData.category || 'Clothing'}
- Brand: ${productData.brand || 'Not specified'}
- Fit: ${productData.fit || 'Regular Fit'}
- Available Sizes: ${productData.availableSizes?.join(', ')}`;
// Add material information if available
if (productData.materials?.length > 0) {
prompt += `\n\nMATERIALS:
${productData.materials.map(m => `- ${m.material}: ${m.percentage}%`).join('\n')}
Calculated Stretch Factor: ${this.calculateMaterialStretch(productData.materials)}%`;
}
// Add review statistics if available
if (productData.ratings?.fitFeedback) {
prompt += `\n\nCUSTOMER FEEDBACK:`;
Object.entries(productData.ratings.fitFeedback).forEach(([aspect, data]) => {
prompt += `\n- ${aspect}: ${data.response} (${data.percentage}% of customers)`;
});
}
// Add size chart and measurements
prompt += `\n\nSIZE CHART:
${this.formatSizeChart(sizeChart)}
USER MEASUREMENTS:
${Object.entries(measurements)
.map(([key, value]) => `- ${key}: ${value}cm`)
.join('\n')}
PREFERENCES:
- Preferred Fit: ${userProfile.preferredFit || 'Regular'}
- Size Preference: ${userProfile.sizePreference || 'Standard'}
Provide a size recommendation using only these available sizes: ${productData.availableSizes?.join(', ')}
Include exact measurements in your reasoning.`;
return prompt;
}
Why Gemini Nano?
Privacy by Design
- All processing happens on the device
- No measurement data ever leaves the user's computer
- Compliant with global privacy regulations
Contextual Understanding
- Analyzes multiple factors simultaneously
- Learns from user feedback
- Adapts to brand-specific patterns
Core APIs Utilized Our solution primarily leverages two of Chrome's built-in Gemini Nano APIs:
- Prompt API (ai.languageModel): Powers our core size analysis engine
- Summarization API: Processes product descriptions and review data
🛠 Technical Deep Dive
Architecture Overview

Smart Product Detection
// Intelligent product page analysis
class ProductAnalyzer {
async analyze() {
try {
// Get basic product information
const basicInfo = await this.getBasicInfo();
// Get size chart and normalize measurements
const sizeInfo = await this.getSizeInfo();
// Extract material composition
const materials = await this.getMaterials();
// Analyze customer reviews for fit feedback
const reviewStats = await this.getReviewStats();
return {
...basicInfo,
sizeChart: sizeInfo.sizeChart,
availableSizes: sizeInfo.availableSizes,
materials,
ratings: reviewStats
};
} catch (error) {
console.error('Analysis error:', error);
throw new Error('Could not analyze product');
}
}
}
🎨 User Experience & Interface
We've created an intuitive interface that enhances the shopping experience:

Profile Management
User can enter his body measurements and preference or upload it as json file too.
// User profile component with measurement management
const UserProfile = () => {
const [measurements, setMeasurements] = useState({});
const [activeSection, setActiveSection] = useState('personal');
/********
{
"age": "30",
"bicep": "27",
"calf": "38",
"chest": "94",
"commonIssues": [],
"forearm": "24",
"gender": "male",
"height": "170",
"hips": "106",
"lastUpdated": "2024-11-26T12:34:00.132Z",
"neck": "37",
"preferredFit": "regular",
"sizePreference": "depends",
"thigh": "54",
"waist": "78",
"weight": "70",
"exportDate": "2024-11-30T08:41:02.327Z"
}
******/
const MEASUREMENT_SCHEMA = {
upperBody: {
title: 'Upper Body Measurements',
fields: {
chest: {
label: 'Chest',
type: 'number',
unit: 'cm',
instructions: 'Measure around the fullest part'
},
// ... other measurements
}
}
// ... other sections
};
return (
<div className="space-y-6">
{Object.entries(MEASUREMENT_SCHEMA).map(([section, data]) => (
<Panel key={section}>
<h3>{data.title}</h3>
<div className="grid grid-cols-2 gap-4">
{/* Measurement input fields */}
</div>
</Panel>
))}
</div>
);
};
Dynamic Recommendations
Once all user profile details are saved you can visit any shopping page (eg. myntra) and analyze the product.

// Product analysis display with confidence indicators
const ProductAnalysis = ({ analysis }) => {
const { sizeRecommendation, materialProperties } = analysis;
return (
<div className="analysis-container">
<div className="recommendation-card">
<h2>Size {sizeRecommendation.size}</h2>
<ConfidenceIndicator level={sizeRecommendation.confidence} />
<MaterialAnalysis properties={materialProperties} />
<FitExplanation reasoning={sizeRecommendation.reasoning} />
</div>
</div>
);
};

🚀 Impact & Future Vision
Current Impact
- 40-50% reduction in returns during pilot tests
- $15-20 saved per prevented return
- Improved customer confidence in online purchases
Future Enhancements
Computer Vision Integration
- Automatic measurements from photos
- Real-time size updates based on body changes
Enhanced Learning
- Brand-specific sizing patterns
- Regional variation analysis
- Seasonal adjustment factors
Expanded Features
- Style recommendations
- Wardrobe integration
- Cross-platform synchronization
🔍 For Developers
Getting Started
// manifest.json configuration
{
"manifest_version": 3,
"name": "SmartFit",
"version": "1.0.0",
"permissions": [
"storage",
"activeTab",
"scripting"
],
"host_permissions": [
"*://*.myntra.com/*"
],
"background": {
"service_worker": "background.js"
}
}
Key Components:
- Content Script: Analyzes product pages
- Background Service: Runs Gemini Nano
- Popup Interface: User interaction
- Storage Manager: Secure data handling
🌟 Why This Matters for Everyone
For Shoppers:
- Confident online shopping
- Fewer returns
- Time and money saved
For Retailers:
- Reduced return costs
- Higher customer satisfaction
- Improved inventory management
For the Environment:
- Reduced shipping emissions
- Less packaging waste
- Sustainable fashion promotion
🎯 Conclusion: Beyond Size Recommendations
SmartFit demonstrates how on-device AI can transform everyday experiences while preserving privacy. It's not just about finding the right size – it's about creating a sustainable, efficient, and enjoyable shopping experience for everyone.
This solution sets a new standard for what's possible with on-device AI, proving that powerful, privacy-conscious applications can solve real-world problems at scale.
Built With
- chrome
- gemini
- javascript
- llm
- node.js
- preact


Log in or sign up for Devpost to join the conversation.