Smart Collaboration Thumbnail Generator π€π¨
What Is This?
Your Thumbnail Crafter Space now has AI-powered logo fetching! When you ask HuggingChat to create a collaboration thumbnail, it will:
- Search the web for the partner company's logo
- Download and process the logo automatically
- Load your Space with the appropriate layout
- Inject the logo into the placeholder
- Export the final thumbnail and return it
Example Use Cases
In HuggingChat
You: "Create a collaboration thumbnail for Hugging Face and Nvidia
using the Serious Collab layout with a white background"
HuggingChat calls your Space β
π‘ Searches web for "Nvidia logo PNG"
β¬οΈ Downloads the logo
π¨ Loads Serious Collab layout
πΌοΈ Replaces placeholder with Nvidia logo
π€ Returns completed thumbnail
You receive: A professional thumbnail ready to use!
More Examples
"Generate a Fun Collab thumbnail for Hugging Face and OpenAI"
"Create an Academia Hub collab thumbnail for Hugging Face and Stanford"
"Make a collaboration thumbnail for Hugging Face and Google
with a light blue background"
How It Works
The Complete Workflow
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. HuggingChat β
β User asks for collaboration thumbnail β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 2. Your MCP Server (Python) β
β β’ Parses request β
β β’ Searches DuckDuckGo for company logo β
β β’ Downloads and processes logo image β
β β’ Resizes, adds transparency β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 3. Playwright Browser Automation β
β β’ Launches headless Chrome β
β β’ Opens your React app β
β β’ Waits for window.thumbnailAPI β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 4. Your React App (window.thumbnailAPI) β
β β’ thumbnailAPI.loadLayout('seriousCollab') β
β β’ thumbnailAPI.setBgColor('#ffffff') β
β β’ thumbnailAPI.replaceLogoPlaceholder(...) β
β β’ thumbnailAPI.exportCanvas() β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 5. Return to HuggingChat β
β Base64-encoded PNG thumbnail β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
Available Tools
1. generate_collab_thumbnail
Generate a collaboration thumbnail with automatic logo fetching.
Parameters:
partner_name(required): Company name (e.g., "Nvidia", "Google", "Microsoft")layout(optional): Layout ID - "seriousCollab" (default), "funCollab", "academiaHub", "sandwich", "impactTitle"partner_logo_url(optional): Direct logo URL if you have onetitle(optional): Custom title textbg_color(optional): Background color hex (default: "#ffffff")canvas_size(optional): "default" (1200x675), "linkedin" (1200x627), "hf" (1160x580)
Example Request:
{
"name": "generate_collab_thumbnail",
"arguments": {
"partner_name": "Nvidia",
"layout": "seriousCollab",
"bg_color": "#f0f0f0"
}
}
Returns:
{
"success": true,
"image": "data:image/png;base64,...",
"width": 1200,
"height": 675,
"partner_name": "Nvidia",
"layout_used": "seriousCollab",
"logo_fetched": true
}
2. search_logo
Just search for a logo without generating a thumbnail.
Parameters:
company_name(required): Company to search for
Example:
{
"name": "search_logo",
"arguments": {
"company_name": "OpenAI"
}
}
3. get_available_layouts
List all available collaboration layouts.
window.thumbnailAPI Reference
Your React app now exposes a programmatic API for browser automation:
window.thumbnailAPI = {
// Load a layout by ID
loadLayout(layoutId: string): boolean
// Set background color
setBgColor(color: string): boolean
// Replace logo placeholder with new image
replaceLogoPlaceholder(imageDataUri: string): boolean
// Add image at specific position
addImage(dataUri: string, x: number, y: number, w?: number, h?: number): boolean
// Update text content
updateText(identifier: string, newText: string): boolean
// Set canvas size
setCanvasSize(size: 'default' | 'linkedin' | 'hf'): boolean
// Export canvas as data URL
exportCanvas(): Promise<string>
// Get current state
getInfo(): object
}
You can also use this API manually in the browser console for testing:
// Open your Space in browser
// Open DevTools Console (F12)
// Load a layout
window.thumbnailAPI.loadLayout('seriousCollab')
// Set background
window.thumbnailAPI.setBgColor('#e3f2fd')
// Replace logo with any data URI
window.thumbnailAPI.replaceLogoPlaceholder('data:image/png;base64,...')
// Export
const dataUrl = await window.thumbnailAPI.exportCanvas()
Deployment Steps
1. Build Your React App
npm run build
This creates the dist/ folder with your production frontend.
2. Choose Which MCP Server to Use
Option A: Smart Server (Recommended)
# Rename to use the smart server
mv mcp_server_smart.py main.py
Option B: Keep Both
Keep both files and update Dockerfile to use mcp_server_smart.py
3. Update Dockerfile
# Copy the smart MCP server
COPY mcp_server_smart.py main.py
# OR
COPY mcp_server_smart.py .
# Update CMD
CMD ["uvicorn", "mcp_server_smart:app", "--host", "0.0.0.0", "--port", "7860"]
4. Install Playwright Browsers in Dockerfile
Add to your Dockerfile:
# After installing Python packages
RUN playwright install chromium
RUN playwright install-deps chromium
5. Deploy to Hugging Face
git add -A
git commit -m "feat: Add smart collaboration thumbnail generation with logo fetching"
git push
6. Wait for Build
Hugging Face will build your Docker container (~10-15 minutes).
7. Test the Endpoint
curl -X POST https://huggingface.co/spaces/YOUR-USERNAME/Thumbnail-Crafter.mini/tools \
-H "Content-Type: application/json" \
-d '{
"name": "generate_collab_thumbnail",
"arguments": {
"partner_name": "Nvidia",
"layout": "seriousCollab"
}
}'
8. Register in HuggingChat
- Go to HuggingChat β Settings β MCP Servers
- Add your Space URL
- Enable it
9. Use It!
User in HuggingChat:
"Create a collab thumbnail for Hugging Face and Nvidia"
HuggingChat:
*generates thumbnail automatically*
Here's your collaboration thumbnail! [shows image]
Local Testing
Test the Smart Server Locally
# Install dependencies
pip install -r requirements.txt
# Install Playwright browsers
playwright install chromium
# Start your React app (in one terminal)
npm run dev
# Start the MCP server (in another terminal)
python mcp_server_smart.py
Test Logo Fetching
curl -X POST http://localhost:7860/tools \
-H "Content-Type: application/json" \
-d '{
"name": "search_logo",
"arguments": {"company_name": "Google"}
}'
Test Full Workflow
curl -X POST http://localhost:7860/tools \
-H "Content-Type: application/json" \
-d '{
"name": "generate_collab_thumbnail",
"arguments": {
"partner_name": "Microsoft",
"layout": "seriousCollab",
"bg_color": "#ffffff"
}
}'
Troubleshooting
Logo Not Found
Problem: Can't find logo for company X
Solutions:
- Try a more specific name: "Microsoft Corporation" instead of "MS"
- Provide direct logo URL:
partner_logo_url: "https://..." - Use a well-known variant: "Meta" instead of "Facebook"
Logo Not Replacing Placeholder
Problem: Logo fetched but not showing in thumbnail
Solutions:
- Check layout has a logo placeholder:
seriousCollab,funCollab,academiaHubdo - Check browser console logs for errors
- Verify window.thumbnailAPI is loaded
Browser Automation Fails
Problem: Playwright can't open the app
Solutions:
- Ensure React app is running at APP_URL
- Check Playwright is installed:
playwright install chromium - Check firewall/network issues
- Try increasing timeouts in Python code
Image Quality Issues
Problem: Logo looks pixelated or wrong size
Solutions:
- Adjust
target_sizeinprocess_logo_image() - Search for higher resolution: add "high resolution" to search query
- Provide direct URL to vector/high-res logo
Performance Considerations
- Logo Fetching: 2-5 seconds
- Browser Launch: 1-3 seconds
- Layout Rendering: 1-2 seconds
- Export: 0.5-1 second
Total Time: ~5-10 seconds per thumbnail
To improve:
- Keep browser instance warm (already implemented)
- Cache fetched logos (TODO)
- Pre-download common logos (TODO)
Security & Privacy
- Logos are fetched from public web sources (DuckDuckGo Images)
- No API keys required for image search
- All processing happens server-side
- No user data is stored
- Respects robots.txt and rate limits
Future Enhancements
- Cache frequently used logos
- Support for multiple logos (three-way collabs)
- Custom logo positioning
- Batch generation
- Video thumbnail generation
- Real-time preview in HuggingChat
Built with Claude Code π€
Questions? Check the main MCP_DEPLOYMENT_GUIDE.md