Ghanmidev2012 commited on
Commit
1c03b1a
·
verified ·
1 Parent(s): caa608b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +33 -36
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Mon App AI Gratuite</title>
7
  <style>
8
  body { font-family: sans-serif; padding: 20px; max-width: 600px; margin: 0 auto; background-color: #f9fafb; color: #1f2937; }
9
  h2 { color: #111827; }
@@ -16,16 +16,18 @@
16
  <body>
17
 
18
  <h2>Mon Application AI Statique</h2>
19
- <p>Écris une demande (en anglais ou en français) pour tester le modèle IA :</p>
20
 
21
- <textarea id="prompt" placeholder="Ex: Write a short story about a robot..."></textarea>
22
  <br>
23
- <button onclick="generateText()">Générer une réponse</button>
24
 
25
  <h3>Résultat :</h3>
26
  <div id="output">La réponse apparaîtra ici...</div>
27
 
28
- <script>
 
 
29
  async function generateText() {
30
  const promptValue = document.getElementById('prompt').value;
31
  const outputDiv = document.getElementById('output');
@@ -37,49 +39,44 @@
37
 
38
  outputDiv.innerText = "L'IA réfléchit...";
39
 
40
- // ⚠️ METS TON NOUVEAU JETON GÉNÉRÉ ICI ENTRE LES GUILLEMETS ⚠️
41
- const HF_TOKEN = "METS_TON_NOUVEAU_TOKEN_ICI";
42
 
43
- try {
44
- const response = await fetch("https://huggingface.co", {
45
- method: "POST",
46
- headers: {
47
- "Authorization": `Bearer ${HF_TOKEN}`,
48
- "Content-Type": "application/json"
49
- },
50
- body: JSON.stringify({
51
- inputs: promptValue,
52
- parameters: { max_new_tokens: 250 }
53
- })
54
- });
55
 
56
- const data = await response.json();
57
-
58
- // Gestion du chargement du modèle
59
- if (data.error) {
60
- if (data.estimated_time) {
61
- outputDiv.innerText = `Le modèle se réveille. Réessaie dans environ ${Math.round(data.estimated_time)} secondes.`;
62
- } else {
63
- outputDiv.innerText = "Erreur API : " + data.error;
64
  }
65
- return;
66
- }
67
 
68
- // Affichage du résultat
69
- if (Array.isArray(data) && data[0].generated_text) {
70
- outputDiv.innerText = data[0].generated_text;
71
- } else if (data.generated_text) {
72
- outputDiv.innerText = data.generated_text;
73
  } else {
74
- outputDiv.innerText = "Réponse reçue, mais format inconnu.";
75
  }
76
 
77
  } catch (error) {
78
- outputDiv.innerText = "Erreur de connexion : " + error.message;
 
 
 
 
79
  }
80
  }
 
 
81
  </script>
82
 
83
  </body>
84
  </html>
85
 
 
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Mon App AI Gratuite (Sécurisée)</title>
7
  <style>
8
  body { font-family: sans-serif; padding: 20px; max-width: 600px; margin: 0 auto; background-color: #f9fafb; color: #1f2937; }
9
  h2 { color: #111827; }
 
16
  <body>
17
 
18
  <h2>Mon Application AI Statique</h2>
19
+ <p>Écris une demande pour tester le modèle IA :</p>
20
 
21
+ <textarea id="prompt" placeholder="Ex: Raconte une histoire courte..."></textarea>
22
  <br>
23
+ <button id="generateBtn">Générer une réponse</button>
24
 
25
  <h3>Résultat :</h3>
26
  <div id="output">La réponse apparaîtra ici...</div>
27
 
28
+ <script type="module">
29
+ import { HfInference } from "https://esm.sh";
30
+
31
  async function generateText() {
32
  const promptValue = document.getElementById('prompt').value;
33
  const outputDiv = document.getElementById('output');
 
39
 
40
  outputDiv.innerText = "L'IA réfléchit...";
41
 
42
+ // 🔐 Récupération sécurisée du token depuis les Secrets de l'Espace
43
+ const HF_TOKEN = window.huggingface?.variables?.HF_TOKEN;
44
 
45
+ if (!HF_TOKEN) {
46
+ outputDiv.innerText = "Erreur : Le Secret 'HF_TOKEN' n'est pas configuré dans les paramètres du Space.";
47
+ return;
48
+ }
 
 
 
 
 
 
 
 
49
 
50
+ try {
51
+ const hf = new HfInference(HF_TOKEN);
52
+ const response = await hf.textGeneration({
53
+ model: 'HuggingFaceH4/zephyr-7b-beta',
54
+ inputs: promptValue,
55
+ parameters: {
56
+ max_new_tokens: 250,
57
+ return_full_text: false
58
  }
59
+ });
 
60
 
61
+ if (response && response.generated_text) {
62
+ outputDiv.innerText = response.generated_text;
 
 
 
63
  } else {
64
+ outputDiv.innerText = "Réponse reçue, mais vide.";
65
  }
66
 
67
  } catch (error) {
68
+ if (error.message.includes("loading")) {
69
+ outputDiv.innerText = "Le modèle charge sur les serveurs. Réessaye dans un instant.";
70
+ } else {
71
+ outputDiv.innerText = "Erreur : " + error.message;
72
+ }
73
  }
74
  }
75
+
76
+ document.getElementById('generateBtn').addEventListener('click', generateText);
77
  </script>
78
 
79
  </body>
80
  </html>
81
 
82
+