Skip to content

Commit 5f498f5

Browse files
committed
feature #851 [Demo] Add smart cropping with Hugging Face to demo (chr-hertel)
This PR was merged into the main branch. Discussion ---------- [Demo] Add smart cropping with Hugging Face to demo | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | | Issues | | License | MIT Bringing in the first non-chatbot example - sitting on top of Hugging Face. The frontend & resampler implementation is rather bad, but will have another look if time permits - and i guess the idea is clear. https://github.com/user-attachments/assets/95a82a83-ff80-44e9-9405-65ae59a89ef1 Commits ------- a1bb014 Add smart cropping example to demo
2 parents e627c06 + a1bb014 commit 5f498f5

File tree

26 files changed

+617
-45
lines changed

26 files changed

+617
-45
lines changed

demo/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ APP_SECRET=ccb9dca72dce53c683eaaf775bfdb253
2222
CHROMADB_HOST=chromadb
2323
CHROMADB_PORT=8080
2424
OPENAI_API_KEY=sk-...
25+
HUGGINGFACE_API_KEY=hf-...

demo/assets/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'bootstrap/dist/css/bootstrap.min.css';
33
import './styles/app.css';
44
import './styles/audio.css';
55
import './styles/blog.css';
6+
import './styles/crop.css';
67
import './styles/stream.css';
78
import './styles/youtube.css';
89
import './styles/video.css';

demo/assets/controllers.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"controllers": {
3+
"@symfony/ux-dropzone": {
4+
"dropzone": {
5+
"enabled": true,
6+
"fetch": "eager",
7+
"autoimport": {
8+
"@symfony/ux-dropzone/dist/style.min.css": true
9+
}
10+
}
11+
},
312
"@symfony/ux-live-component": {
413
"live": {
514
"enabled": true,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
3+
export default class extends Controller {
4+
connect() {
5+
this.element.addEventListener('dropzone:change', this._onChange.bind(this));
6+
this.element.addEventListener('dropzone:clear', this._onClear);
7+
}
8+
9+
disconnect() {
10+
this.element.removeEventListener('dropzone:change', this._onChange.bind(this));
11+
this.element.removeEventListener('dropzone:clear', this._onClear);
12+
}
13+
14+
async _onChange(event) {
15+
const cropComponent = document.getElementById('crop-component').__component;
16+
17+
cropComponent.set('imageData', await this.blobToBase64(event.detail));
18+
}
19+
20+
_onClear(event) {
21+
const cropComponent = document.getElementById('crop-component').__component;
22+
23+
cropComponent.set('imageData', null);
24+
}
25+
26+
blobToBase64(blob) {
27+
return new Promise((resolve) => {
28+
const reader = new FileReader();
29+
reader.readAsDataURL(blob);
30+
reader.onloadend = () => resolve(reader.result);
31+
});
32+
}
33+
}
Lines changed: 1 addition & 0 deletions
Loading

demo/assets/styles/crop.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.crop {
2+
body&, .card-img-top {
3+
background: rgb(34,34,34);
4+
background: linear-gradient(0deg, rgb(209, 14, 205) 0%, rgb(120, 21, 135) 100%);
5+
}
6+
7+
.card-img-top {
8+
color: #ffffff;
9+
}
10+
11+
& footer {
12+
color: #ffffff;
13+
14+
a {
15+
color: #ffffff;
16+
}
17+
}
18+
}

demo/composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"php": ">=8.4",
88
"ext-ctype": "*",
99
"ext-iconv": "*",
10+
"ext-gd": "*",
1011
"codewithkyrian/chromadb-php": "^0.4.0",
1112
"league/commonmark": "^2.7",
1213
"mcp/sdk": "@dev",
@@ -22,13 +23,16 @@
2223
"symfony/dom-crawler": "~7.3.0",
2324
"symfony/dotenv": "~7.3.0",
2425
"symfony/flex": "^2.5",
26+
"symfony/form": "~7.3.0",
2527
"symfony/framework-bundle": "~7.3.0",
2628
"symfony/http-client": "~7.3.0",
2729
"symfony/mcp-bundle": "@dev",
30+
"symfony/mime": "~7.3.0",
2831
"symfony/monolog-bundle": "^3.10",
2932
"symfony/runtime": "~7.3.0",
3033
"symfony/twig-bundle": "~7.3.0",
3134
"symfony/uid": "~7.3.0",
35+
"symfony/ux-dropzone": "^2.31",
3236
"symfony/ux-icons": "^2.25",
3337
"symfony/ux-live-component": "^2.25",
3438
"symfony/ux-turbo": "^2.25",

demo/config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
1818
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
1919
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
20+
Symfony\UX\Dropzone\DropzoneBundle::class => ['all' => true],
2021
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
2122
Symfony\UX\LiveComponent\LiveComponentBundle::class => ['all' => true],
2223
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],

demo/config/packages/ai.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ ai:
22
platform:
33
openai:
44
api_key: '%env(OPENAI_API_KEY)%'
5+
huggingface:
6+
api_key: '%env(HUGGINGFACE_API_KEY)%'
57
agent:
68
blog:
9+
platform: 'ai.platform.openai'
710
model: 'gpt-4o-mini'
811
tools:
912
- 'Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch'
@@ -12,14 +15,17 @@ ai:
1215
description: 'Provides the current date and time.'
1316
method: 'now'
1417
stream:
18+
platform: 'ai.platform.openai'
1519
model: 'gpt-4o-mini'
1620
prompt:
1721
file: '%kernel.project_dir%/prompts/stream-chat.txt'
1822
tools: false
1923
youtube:
24+
platform: 'ai.platform.openai'
2025
model: 'gpt-4o-mini'
2126
tools: false
2227
wikipedia:
28+
platform: 'ai.platform.openai'
2329
model:
2430
name: 'gpt-4o-mini'
2531
options:
@@ -31,6 +37,7 @@ ai:
3137
- 'Symfony\AI\Agent\Toolbox\Tool\Wikipedia'
3238
include_sources: true
3339
audio:
40+
platform: 'ai.platform.openai'
3441
model: 'gpt-4o-mini?temperature=1.0'
3542
prompt: 'You are a friendly chatbot that likes to have a conversation with users and asks them some questions.'
3643
tools:
@@ -39,14 +46,17 @@ ai:
3946
name: 'symfony_blog'
4047
description: 'Can answer questions based on the Symfony blog.'
4148
orchestrator:
49+
platform: 'ai.platform.openai'
4250
model: 'gpt-4o-mini'
4351
prompt: 'You are an intelligent agent orchestrator that routes user questions to specialized agents.'
4452
tools: false
4553
technical:
54+
platform: 'ai.platform.openai'
4655
model: 'gpt-4o-mini'
4756
prompt: 'You are a technical support specialist. Help users resolve bugs, problems, and technical errors.'
4857
tools: false
4958
fallback:
59+
platform: 'ai.platform.openai'
5060
model: 'gpt-4o-mini'
5161
prompt: 'You are a helpful general assistant. Assist users with any questions or tasks they may have.'
5262
tools: false
@@ -62,6 +72,7 @@ ai:
6272
collection: 'symfony_blog'
6373
vectorizer:
6474
openai:
75+
platform: 'ai.platform.openai'
6576
model: 'text-embedding-ada-002'
6677
indexer:
6778
blog:

demo/config/packages/csrf.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Enable stateless CSRF protection for forms and logins/logouts
2+
framework:
3+
form:
4+
csrf_protection:
5+
token_id: submit
6+
7+
csrf_protection:
8+
stateless_token_ids:
9+
- submit
10+
- authenticate
11+
- logout

0 commit comments

Comments
 (0)