Abmacode12 commited on
Commit
1900a01
·
verified ·
1 Parent(s): 357a4bf

CODE D'INTÉGRATION PROFESSIONNEL :

Browse files

1. HTML - Structure modifiée (à insérer dans le thème existant) :
html
<!-- REMPLACE la section "Bonjour je suis votre assistant IA" par : -->
<div id="assistant-ia" style="height: 60vh; overflow-y: auto; padding: 20px; background: white; border-radius: 10px; margin-bottom: 20px;">
<div class="message-ia" style="background: #e3f2fd; padding: 12px; border-radius: 12px; margin-bottom: 15px; max-width: 80%;">
<strong>🐋 La Baleine IA :</strong> Bonjour ! Je suis votre assistante IA créative. Décrivez-moi une image ou une vidéo, et je la générerai pour vous en expliquant chaque étape.
</div>
<!-- Les messages s'ajouteront ici dynamiquement -->
</div>

<!-- REMPLACE la section "Échec du chargement de l'aperçu" par : -->
<div id="apercu-section" style="background: #1a1a1a; color: white; padding: 20px; border-radius: 10px; height: 60vh; overflow-y: auto;">
<h4 style="color: #4fc3f7;">🎬 Zone de Génération</h4>
<p id="statut-generation" style="color: #bbb;">En attente de votre demande...</p>
<div id="resultat-visuel" style="margin-top: 20px; text-align: center;">
<!-- Images/vidéos apparaîtront ici -->
</div>
<div id="controles-generation" style="margin-top: 20px; display: none;">
<button onclick="telechargerMedia()" style="background: #4caf50; color: white; border: none; padding: 10px 15px; border-radius: 6px; margin-right: 10px;">
📥 Télécharger
</button>
<button onclick="genererNouvelleVersion()" style="background: #ff9800; color: white; border: none; padding: 10px 15px; border-radius: 6px;">
🔄 Regénérer
</button>
</div>
</div>
2. JavaScript - Intelligence et Génération (à ajouter dans script.js) :
javascript
// CONFIGURATION PROFESSIONNELLE
const LaBaleineIA = {
token: "hf_votre_token_gratuit", // À configurer sur HuggingFace
endpoints: {
image: "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0",
video: "https://api-inference.huggingface.co/models/cerspense/zeroscope_v2_576w"
},

// Initialisation
init: function() {
console.log("🐋 La Baleine IA initialisée");
this.setupEventListeners();
},

// Configuration des événements
setupEventListeners: function() {
// Récupère la zone de saisie existante
const inputField = document.querySelector('input[placeholder*="Écrivez votre message"], input[placeholder*="écrire"]');
if (inputField) {
inputField.addEventListener('keypress', (e) => {
if (e.key === 'Enter' && e.target.value.trim()) {
this.processerDemande(e.target.value);
e.target.value = '';
}
});
}

// Bouton d'envoi (si existant)
const sendButton = document.querySelector('button:contains("Envoyer"), button:contains("Send")');
if (sendButton) {
sendButton.addEventListener('click', () => {
const input = document.querySelector('input[placeholder*="Écrivez votre message"], input[placeholder*="écrire"]');
if (input && input.value.trim()) {
this.processerDemande(input.value);
input.value = '';
}
});
}
},

// Traiter la demande utilisateur
processerDemande: async function(demande) {
// 1. Afficher le message utilisateur
this.afficherMessage('utilisateur', demande);

// 2. Réponse initiale de La Baleine
this.afficherMessage('ia', `J'ai bien reçu : "${demande}". Je commence la génération...`);

// 3. Analyser la demande pour le type
const type = this.analyserTypeDemande(demande);

// 4. Expliquer les étapes
this.afficherExplication(`Étape 1/3 : Analyse de votre demande...`);
await this.delay(800);

this.afficherExplication(`Étape 2/3 : Préparation de la génération ${type === 'image' ? 'd\'image' : 'de vidéo'}...`);
await this.delay(800);

// 5. Génération
try {
this.afficherExplication(`Étape 3/3 : Génération en cours avec les modèles IA...`);

if (type === 'image') {
await this.genererImage(demande);
} else {
await this.genererVideo(demande);
}

this.afficherMessage('ia', `✅ Génération terminée ! Consultez la colonne de droite pour voir le résultat.`);
this.afficherExplication(`Processus complet terminé avec succès.`);

} catch (error) {
this.afficherMessage('ia', `❌ Désolée, une erreur est survenue : ${error.message}`);
}
},

// Générer une image
genererImage: async function(prompt) {
const response = await fetch(this.endpoints.image, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
inputs: prompt,
parameters: {
num_inference_steps: 30,
guidance_scale: 7.5
}
})
});

if (!response.ok) throw new Error(`Erreur API: ${response.status}`);

const blob = await response.blob();
const urlImage = URL.createObjectURL(blob);

// Afficher dans la colonne droite
this.afficherResultatVisuel('image', urlImage, prompt);

// Sauvegarder pour téléchargement
this.mediaCourant = { type: 'image', url: urlImage, nom: `baleine_${Date.now()}.png` };
},

// Afficher le résultat visuel
afficherResultatVisuel: function(type, url, prompt) {
const section = document.getElementById('apercu-section');
const statut = document.getElementById('statut-generation');
const resultat = document.getElementById('resultat-visuel');
const controles = document.getElementById('controles-generation');

if (statut) statut.textContent = `✅ ${type === 'image' ? 'Image générée' : 'Vidéo générée'}`;

if (resultat) {
if (type === 'image') {
resultat.innerHTML = `
<h5 style="color: #fff; margin-bottom: 15px;">"${prompt}"</h5>
<img src="${url}" alt="Généré par La Baleine"
style="max-width: 100%; border-radius: 10px; box-shadow: 0 5px 20px rgba(0,0,0,0.5);">
`;
} else {
resultat.innerHTML = `
<h5 style="color: #fff; margin-bottom: 15px;">"${prompt}"</h5>
<video src="${url}" controls autoplay
style="max-width: 100%; border-radius: 10px; box-shadow: 0 5px 20px rgba(0,0,0,0.5);">
</video>
`;
}
}

if (controles) controles.style.display = 'block';

// Scroll automatique
section.scrollTop = section.scrollHeight;
},

// Afficher un message dans le chat
afficherMessage: function(auteur, contenu) {
const chat = document.getElementById('assistant-ia');
if (!chat) return;

const messageDiv = document.createElement('div');
messageDiv.className = `message-${auteur}`;
messageDiv.style.cssText = `
padding: 12px;
border-radius: 12px;
margin-bottom: 15px;
max-width: 80%;
${auteur === 'utilisateur' ?
'background: #007bff; color: white; margin-left: auto;' :
'background: #e3f2fd; color: #333;'}
`;

messageDiv.innerHTML = `<strong>${auteur === 'utilisateur' ? '👤 Vous' : '🐋 La Baleine'}:</strong> ${contenu}`;
chat.appendChild(messageDiv);
chat.scrollTop = chat.scrollHeight;
},

// Afficher une explication technique
afficherExplication: function(texte) {
const chat = document.getElementById('assistant-ia');
if (!chat) return;

const explicationDiv = document.createElement('div');
explicationDiv.style.cssText = `
padding: 10px;
border-radius: 8px;
margin: 5px 0;
background: #f5f5f5;
border-left: 4px solid #4fc3f7;
font-size: 14px;
color: #555;
`;
explicationDiv.innerHTML = `⚙️ ${texte}`;
chat.appendChild(explicationDiv);
chat.scrollTop = chat.scrollHeight;
},

// Analyser le type de demande
analyserTypeDemande: function(demande) {
const motsVideo = ['vidéo', 'film', 'animation', 'mouvement', 'cinéma'];
const contientVideo = motsVideo.some(mot => demande.toLowerCase().includes(mot));
return contientVideo ? 'video' : 'image';
},

// Fonction d'attente
delay: function(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
};

// Fonctions de contrôle
function telechargerMedia() {
if (LaBaleineIA.mediaCourant) {
const a = document.createElement('a');
a.href = LaBaleineIA.mediaCourant.url;
a.download = LaBaleineIA.mediaCourant.nom;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}

function genererNouvelleVersion() {
const dernierMessage = document.querySelector('.message-utilisateur:last-child');
if (dernierMessage) {
const texte = dernierMessage.textContent.replace('👤 Vous:', '').trim();
if (texte) LaBaleineIA.processerDemande(texte);
}
}

// Initialiser au chargement
document.addEventListener('DOMContentLoaded', () => {
LaBaleineIA.init();
});

Files changed (2) hide show
  1. script.js +214 -1
  2. style.css +37 -1
script.js CHANGED
@@ -1,6 +1,219 @@
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  document.addEventListener('DOMContentLoaded', () => {
3
- // Initialize tooltips for icons
 
4
  const initTooltips = () => {
5
  const buttons = document.querySelectorAll('button');
6
  buttons.forEach(button => {
 
1
 
2
+ // CONFIGURATION PROFESSIONNELLE
3
+ const LaBaleineIA = {
4
+ token: "hf_votre_token_gratuit", // À configurer sur HuggingFace
5
+ endpoints: {
6
+ image: "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0",
7
+ video: "https://api-inference.huggingface.co/models/cerspense/zeroscope_v2_576w"
8
+ },
9
+
10
+ // Initialisation
11
+ init: function() {
12
+ console.log("🐋 La Baleine IA initialisée");
13
+ this.setupEventListeners();
14
+ },
15
+
16
+ // Configuration des événements
17
+ setupEventListeners: function() {
18
+ // Récupère la zone de saisie existante
19
+ const inputField = document.querySelector('input[placeholder*="Écrivez votre message"], input[placeholder*="écrire"]');
20
+ if (inputField) {
21
+ inputField.addEventListener('keypress', (e) => {
22
+ if (e.key === 'Enter' && e.target.value.trim()) {
23
+ this.processerDemande(e.target.value);
24
+ e.target.value = '';
25
+ }
26
+ });
27
+ }
28
+
29
+ // Bouton d'envoi (si existant)
30
+ const sendButton = document.querySelector('button:contains("Envoyer"), button:contains("Send")');
31
+ if (sendButton) {
32
+ sendButton.addEventListener('click', () => {
33
+ const input = document.querySelector('input[placeholder*="Écrivez votre message"], input[placeholder*="écrire"]');
34
+ if (input && input.value.trim()) {
35
+ this.processerDemande(input.value);
36
+ input.value = '';
37
+ }
38
+ });
39
+ }
40
+ },
41
+
42
+ // Traiter la demande utilisateur
43
+ processerDemande: async function(demande) {
44
+ // 1. Afficher le message utilisateur
45
+ this.afficherMessage('utilisateur', demande);
46
+
47
+ // 2. Réponse initiale de La Baleine
48
+ this.afficherMessage('ia', `J'ai bien reçu : "${demande}". Je commence la génération...`);
49
+
50
+ // 3. Analyser la demande pour le type
51
+ const type = this.analyserTypeDemande(demande);
52
+
53
+ // 4. Expliquer les étapes
54
+ this.afficherExplication(`Étape 1/3 : Analyse de votre demande...`);
55
+ await this.delay(800);
56
+
57
+ this.afficherExplication(`Étape 2/3 : Préparation de la génération ${type === 'image' ? 'd\'image' : 'de vidéo'}...`);
58
+ await this.delay(800);
59
+
60
+ // 5. Génération
61
+ try {
62
+ this.afficherExplication(`Étape 3/3 : Génération en cours avec les modèles IA...`);
63
+
64
+ if (type === 'image') {
65
+ await this.genererImage(demande);
66
+ } else {
67
+ await this.genererVideo(demande);
68
+ }
69
+
70
+ this.afficherMessage('ia', `✅ Génération terminée ! Consultez la colonne de droite pour voir le résultat.`);
71
+ this.afficherExplication(`Processus complet terminé avec succès.`);
72
+
73
+ } catch (error) {
74
+ this.afficherMessage('ia', `❌ Désolée, une erreur est survenue : ${error.message}`);
75
+ }
76
+ },
77
+
78
+ // Générer une image
79
+ genererImage: async function(prompt) {
80
+ const response = await fetch(this.endpoints.image, {
81
+ method: 'POST',
82
+ headers: {
83
+ 'Authorization': `Bearer ${this.token}`,
84
+ 'Content-Type': 'application/json'
85
+ },
86
+ body: JSON.stringify({
87
+ inputs: prompt,
88
+ parameters: {
89
+ num_inference_steps: 30,
90
+ guidance_scale: 7.5
91
+ }
92
+ })
93
+ });
94
+
95
+ if (!response.ok) throw new Error(`Erreur API: ${response.status}`);
96
+
97
+ const blob = await response.blob();
98
+ const urlImage = URL.createObjectURL(blob);
99
+
100
+ // Afficher dans la colonne droite
101
+ this.afficherResultatVisuel('image', urlImage, prompt);
102
+
103
+ // Sauvegarder pour téléchargement
104
+ this.mediaCourant = { type: 'image', url: urlImage, nom: `baleine_${Date.now()}.png` };
105
+ },
106
+
107
+ // Afficher le résultat visuel
108
+ afficherResultatVisuel: function(type, url, prompt) {
109
+ const section = document.getElementById('apercu-section');
110
+ const statut = document.getElementById('statut-generation');
111
+ const resultat = document.getElementById('resultat-visuel');
112
+ const controles = document.getElementById('controles-generation');
113
+
114
+ if (statut) statut.textContent = `✅ ${type === 'image' ? 'Image générée' : 'Vidéo générée'}`;
115
+
116
+ if (resultat) {
117
+ if (type === 'image') {
118
+ resultat.innerHTML = `
119
+ <h5 style="color: #fff; margin-bottom: 15px;">"${prompt}"</h5>
120
+ <img src="${url}" alt="Généré par La Baleine"
121
+ style="max-width: 100%; border-radius: 10px; box-shadow: 0 5px 20px rgba(0,0,0,0.5);">
122
+ `;
123
+ } else {
124
+ resultat.innerHTML = `
125
+ <h5 style="color: #fff; margin-bottom: 15px;">"${prompt}"</h5>
126
+ <video src="${url}" controls autoplay
127
+ style="max-width: 100%; border-radius: 10px; box-shadow: 0 5px 20px rgba(0,0,0,0.5);">
128
+ </video>
129
+ `;
130
+ }
131
+ }
132
+
133
+ if (controles) controles.style.display = 'block';
134
+
135
+ // Scroll automatique
136
+ section.scrollTop = section.scrollHeight;
137
+ },
138
+
139
+ // Afficher un message dans le chat
140
+ afficherMessage: function(auteur, contenu) {
141
+ const chat = document.getElementById('assistant-ia');
142
+ if (!chat) return;
143
+
144
+ const messageDiv = document.createElement('div');
145
+ messageDiv.className = `message-${auteur}`;
146
+ messageDiv.style.cssText = `
147
+ padding: 12px;
148
+ border-radius: 12px;
149
+ margin-bottom: 15px;
150
+ max-width: 80%;
151
+ ${auteur === 'utilisateur' ?
152
+ 'background: #007bff; color: white; margin-left: auto;' :
153
+ 'background: #e3f2fd; color: #333;'}
154
+ `;
155
+
156
+ messageDiv.innerHTML = `<strong>${auteur === 'utilisateur' ? '👤 Vous' : '🐋 La Baleine'}:</strong> ${contenu}`;
157
+ chat.appendChild(messageDiv);
158
+ chat.scrollTop = chat.scrollHeight;
159
+ },
160
+
161
+ // Afficher une explication technique
162
+ afficherExplication: function(texte) {
163
+ const chat = document.getElementById('assistant-ia');
164
+ if (!chat) return;
165
+
166
+ const explicationDiv = document.createElement('div');
167
+ explicationDiv.style.cssText = `
168
+ padding: 10px;
169
+ border-radius: 8px;
170
+ margin: 5px 0;
171
+ background: #f5f5f5;
172
+ border-left: 4px solid #4fc3f7;
173
+ font-size: 14px;
174
+ color: #555;
175
+ `;
176
+ explicationDiv.innerHTML = `⚙️ ${texte}`;
177
+ chat.appendChild(explicationDiv);
178
+ chat.scrollTop = chat.scrollHeight;
179
+ },
180
+
181
+ // Analyser le type de demande
182
+ analyserTypeDemande: function(demande) {
183
+ const motsVideo = ['vidéo', 'film', 'animation', 'mouvement', 'cinéma'];
184
+ const contientVideo = motsVideo.some(mot => demande.toLowerCase().includes(mot));
185
+ return contientVideo ? 'video' : 'image';
186
+ },
187
+
188
+ // Fonction d'attente
189
+ delay: function(ms) {
190
+ return new Promise(resolve => setTimeout(resolve, ms));
191
+ }
192
+ };
193
+
194
+ // Fonctions de contrôle
195
+ function telechargerMedia() {
196
+ if (LaBaleineIA.mediaCourant) {
197
+ const a = document.createElement('a');
198
+ a.href = LaBaleineIA.mediaCourant.url;
199
+ a.download = LaBaleineIA.mediaCourant.nom;
200
+ document.body.appendChild(a);
201
+ a.click();
202
+ document.body.removeChild(a);
203
+ }
204
+ }
205
+
206
+ function genererNouvelleVersion() {
207
+ const dernierMessage = document.querySelector('.message-utilisateur:last-child');
208
+ if (dernierMessage) {
209
+ const texte = dernierMessage.textContent.replace('👤 Vous:', '').trim();
210
+ if (texte) LaBaleineIA.processerDemande(texte);
211
+ }
212
+ }
213
+
214
  document.addEventListener('DOMContentLoaded', () => {
215
+ LaBaleineIA.init();
216
+ // Initialize tooltips for icons
217
  const initTooltips = () => {
218
  const buttons = document.querySelectorAll('button');
219
  buttons.forEach(button => {
style.css CHANGED
@@ -83,7 +83,7 @@ input:focus, button:focus {
83
  font-size: 0.875rem;
84
  }
85
  /* Chat message styles */
86
- #chatMessages {
87
  flex: 1;
88
  overflow-y: auto;
89
  padding: 1rem;
@@ -92,6 +92,42 @@ input:focus, button:focus {
92
  gap: 0.75rem;
93
  }
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  .msg {
96
  word-break: break-word;
97
  white-space: pre-wrap;
 
83
  font-size: 0.875rem;
84
  }
85
  /* Chat message styles */
86
+ #chatMessages, #assistant-ia {
87
  flex: 1;
88
  overflow-y: auto;
89
  padding: 1rem;
 
92
  gap: 0.75rem;
93
  }
94
 
95
+ .message-ia {
96
+ background: #e3f2fd;
97
+ padding: 12px;
98
+ border-radius: 12px;
99
+ margin-bottom: 15px;
100
+ max-width: 80%;
101
+ color: #333;
102
+ }
103
+
104
+ .message-utilisateur {
105
+ background: #007bff;
106
+ color: white;
107
+ padding: 12px;
108
+ border-radius: 12px;
109
+ margin-bottom: 15px;
110
+ max-width: 80%;
111
+ margin-left: auto;
112
+ }
113
+
114
+ #apercu-section {
115
+ background: #1a1a1a;
116
+ color: white;
117
+ padding: 20px;
118
+ border-radius: 10px;
119
+ height: 60vh;
120
+ overflow-y: auto;
121
+ }
122
+
123
+ #controles-generation button {
124
+ transition: all 0.2s ease;
125
+ }
126
+
127
+ #controles-generation button:hover {
128
+ transform: translateY(-2px);
129
+ box-shadow: 0 4px 8px rgba(0,0,0,0.2);
130
+ }
131
  .msg {
132
  word-break: break-word;
133
  white-space: pre-wrap;