File size: 11,030 Bytes
65493c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# 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:
1. **Search the web** for the partner company's logo
2. **Download and process** the logo automatically
3. **Load your Space** with the appropriate layout
4. **Inject the logo** into the placeholder
5. **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 one
- `title` (optional): Custom title text
- `bg_color` (optional): Background color hex (default: "#ffffff")
- `canvas_size` (optional): "default" (1200x675), "linkedin" (1200x627), "hf" (1160x580)
**Example Request:**
```json
{
"name": "generate_collab_thumbnail",
"arguments": {
"partner_name": "Nvidia",
"layout": "seriousCollab",
"bg_color": "#f0f0f0"
}
}
```
**Returns:**
```json
{
"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:**
```json
{
"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:
```typescript
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:
```javascript
// 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
```bash
npm run build
```
This creates the `dist/` folder with your production frontend.
### 2. Choose Which MCP Server to Use
**Option A: Smart Server (Recommended)**
```bash
# 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
```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:
```dockerfile
# After installing Python packages
RUN playwright install chromium
RUN playwright install-deps chromium
```
### 5. Deploy to Hugging Face
```bash
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
```bash
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
1. Go to HuggingChat β Settings β MCP Servers
2. Add your Space URL
3. 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
```bash
# 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
```bash
curl -X POST http://localhost:7860/tools \
-H "Content-Type: application/json" \
-d '{
"name": "search_logo",
"arguments": {"company_name": "Google"}
}'
```
### Test Full Workflow
```bash
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:**
1. Try a more specific name: "Microsoft Corporation" instead of "MS"
2. Provide direct logo URL: `partner_logo_url: "https://..."`
3. Use a well-known variant: "Meta" instead of "Facebook"
### Logo Not Replacing Placeholder
**Problem:** Logo fetched but not showing in thumbnail
**Solutions:**
1. Check layout has a logo placeholder: `seriousCollab`, `funCollab`, `academiaHub` do
2. Check browser console logs for errors
3. Verify window.thumbnailAPI is loaded
### Browser Automation Fails
**Problem:** Playwright can't open the app
**Solutions:**
1. Ensure React app is running at APP_URL
2. Check Playwright is installed: `playwright install chromium`
3. Check firewall/network issues
4. Try increasing timeouts in Python code
### Image Quality Issues
**Problem:** Logo looks pixelated or wrong size
**Solutions:**
1. Adjust `target_size` in `process_logo_image()`
2. Search for higher resolution: add "high resolution" to search query
3. 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](./MCP_DEPLOYMENT_GUIDE.md)
|