Spaces:
Running
Running
// Error: No code generated
Browse filesfaut bien que ça envoie la requete à gemini qui met le code
script.js
CHANGED
|
@@ -32,28 +32,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 32 |
try {
|
| 33 |
const tech = document.querySelector('.tech-choice.active').textContent;
|
| 34 |
const prompt = `Create a ${tech} app that ${appDescription.value}`;
|
| 35 |
-
|
| 36 |
// Call Gemini API
|
| 37 |
-
const response = await fetch('https://
|
| 38 |
-
|
| 39 |
-
'Content-Type': 'application/json',
|
| 40 |
-
'Authorization': 'Bearer sk-proj-abc123' // Replace with your OpenAI API key
|
| 41 |
-
},
|
| 42 |
-
method: 'POST',
|
| 43 |
headers: {
|
| 44 |
'Content-Type': 'application/json',
|
| 45 |
},
|
| 46 |
body: JSON.stringify({
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
}]
|
| 52 |
-
temperature: 0.7
|
| 53 |
})
|
| 54 |
});
|
| 55 |
const data = await response.json();
|
| 56 |
-
let generatedCode = data.
|
| 57 |
// Display the code with typewriter effect
|
| 58 |
typeWriterEffect(codeOutput, generatedCode, 10, () => {
|
| 59 |
generateBtn.disabled = false;
|
|
@@ -65,8 +59,11 @@ typeWriterEffect(codeOutput, generatedCode, 10, () => {
|
|
| 65 |
chatSection.classList.remove('hidden');
|
| 66 |
|
| 67 |
// Update preview iframe
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
| 70 |
});
|
| 71 |
} catch (error) {
|
| 72 |
console.error('Error generating code:', error);
|
|
|
|
| 32 |
try {
|
| 33 |
const tech = document.querySelector('.tech-choice.active').textContent;
|
| 34 |
const prompt = `Create a ${tech} app that ${appDescription.value}`;
|
|
|
|
| 35 |
// Call Gemini API
|
| 36 |
+
const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY', {
|
| 37 |
+
method: 'POST',
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
headers: {
|
| 39 |
'Content-Type': 'application/json',
|
| 40 |
},
|
| 41 |
body: JSON.stringify({
|
| 42 |
+
contents: [{
|
| 43 |
+
parts: [{
|
| 44 |
+
text: prompt
|
| 45 |
+
}]
|
| 46 |
+
}]
|
|
|
|
| 47 |
})
|
| 48 |
});
|
| 49 |
const data = await response.json();
|
| 50 |
+
let generatedCode = data.candidates?.[0]?.content?.parts?.[0]?.text || "// Error: No code generated";
|
| 51 |
// Display the code with typewriter effect
|
| 52 |
typeWriterEffect(codeOutput, generatedCode, 10, () => {
|
| 53 |
generateBtn.disabled = false;
|
|
|
|
| 59 |
chatSection.classList.remove('hidden');
|
| 60 |
|
| 61 |
// Update preview iframe
|
| 62 |
+
// Extract just the code block if present
|
| 63 |
+
const codeMatch = generatedCode.match(/```[a-zA-Z]*\n([\s\S]*?)\n```/);
|
| 64 |
+
const codeToShow = codeMatch ? codeMatch[1] : generatedCode;
|
| 65 |
+
const blob = new Blob([codeToShow], {type: 'text/html'});
|
| 66 |
+
previewFrame.src = URL.createObjectURL(blob);
|
| 67 |
});
|
| 68 |
} catch (error) {
|
| 69 |
console.error('Error generating code:', error);
|