hellooooooo000 commited on
Commit
68d874d
·
verified ·
1 Parent(s): 79ed84e

ça envoie un prompt à gemini 2.5 flash sous la forme "cree une app {prompt}" et ensuite ça mmet la preview de l'app et la possibilité de voir le code

Browse files
Files changed (3) hide show
  1. index.html +23 -9
  2. script.js +52 -95
  3. style.css +12 -2
index.html CHANGED
@@ -50,24 +50,38 @@
50
  </button>
51
  </div>
52
  <div class="w-full md:w-1/2">
53
- <div class="bg-gray-900 rounded-lg p-4 h-full">
54
  <div class="flex items-center justify-between mb-4">
55
- <div class="flex gap-2">
56
- <div class="w-3 h-3 rounded-full bg-red-500"></div>
57
- <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
58
- <div class="w-3 h-3 rounded-full bg-green-500"></div>
 
 
 
 
 
 
 
59
  </div>
60
- <span class="text-gray-400 text-sm">app.js</span>
61
  </div>
62
- <pre id="code-output" class="text-gray-200 font-mono text-sm overflow-auto max-h-96 bg-gray-800 p-4 rounded">// Your generated code will appear here...</pre>
 
63
  </div>
64
- </div>
 
 
 
 
 
 
 
65
  </div>
66
  </section>
67
 
68
  <!-- Chat Section -->
69
  <section id="chat" class="bg-white rounded-xl shadow-lg p-8 mb-20 hidden">
70
- <h2 class="text-2xl font-bold text-gray-800 mb-6">Refine Your App</h2>
71
  <div class="flex flex-col h-96 mb-4 border border-gray-300 rounded-lg overflow-hidden">
72
  <div id="chat-messages" class="flex-1 overflow-y-auto p-4 bg-gray-50">
73
  <div class="flex justify-start mb-4">
 
50
  </button>
51
  </div>
52
  <div class="w-full md:w-1/2">
53
+ <div class="bg-gray-900 rounded-lg p-4 h-full flex flex-col">
54
  <div class="flex items-center justify-between mb-4">
55
+ <div class="flex gap-4">
56
+ <button id="view-code-btn" class="active text-gray-400 hover:text-white text-sm font-medium">Code</button>
57
+ <button id="view-preview-btn" class="text-gray-400 hover:text-white text-sm font-medium">Preview</button>
58
+ </div>
59
+ <div class="flex gap-2 items-center">
60
+ <div class="flex gap-2">
61
+ <div class="w-3 h-3 rounded-full bg-red-500"></div>
62
+ <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
63
+ <div class="w-3 h-3 rounded-full bg-green-500"></div>
64
+ </div>
65
+ <span class="text-gray-400 text-sm">app.js</span>
66
  </div>
 
67
  </div>
68
+ <pre id="code-output" class="text-gray-200 font-mono text-sm overflow-auto flex-1 bg-gray-800 p-4 rounded">// Your generated code will appear here...</pre>
69
+ <iframe id="preview-frame" class="hidden w-full h-full bg-white rounded-b-lg"></iframe>
70
  </div>
71
+ </div>
72
+ </div>
73
+ </section>
74
+ <!-- Preview Section -->
75
+ <section id="preview" class="bg-white rounded-xl shadow-lg p-8 mb-6 hidden">
76
+ <h2 class="text-2xl font-bold text-gray-800 mb-6">App Preview</h2>
77
+ <div class="border border-gray-300 rounded-lg overflow-hidden h-96">
78
+ <iframe id="preview-frame" class="w-full h-full"></iframe>
79
  </div>
80
  </section>
81
 
82
  <!-- Chat Section -->
83
  <section id="chat" class="bg-white rounded-xl shadow-lg p-8 mb-20 hidden">
84
+ <h2 class="text-2xl font-bold text-gray-800 mb-6">Refine Your App</h2>
85
  <div class="flex flex-col h-96 mb-4 border border-gray-300 rounded-lg overflow-hidden">
86
  <div id="chat-messages" class="flex-1 overflow-y-auto p-4 bg-gray-50">
87
  <div class="flex justify-start mb-4">
script.js CHANGED
@@ -8,12 +8,15 @@ document.addEventListener('DOMContentLoaded', () => {
8
  choice.classList.add('active');
9
  });
10
  });
11
-
12
  // Code generation
13
  const generateBtn = document.getElementById('generate-btn');
14
  const appDescription = document.getElementById('app-description');
15
  const codeOutput = document.getElementById('code-output');
16
  const chatSection = document.getElementById('chat');
 
 
 
 
17
 
18
  generateBtn.addEventListener('click', async () => {
19
  if (!appDescription.value.trim()) {
@@ -26,12 +29,27 @@ document.addEventListener('DOMContentLoaded', () => {
26
  generateBtn.innerHTML = '<i data-feather="loader" class="animate-spin"></i> Generating...';
27
  feather.replace();
28
 
29
- // Simulate API call to generate code
30
- setTimeout(() => {
31
  const tech = document.querySelector('.tech-choice.active').textContent;
 
32
 
33
- // Example generated code (in a real app this would come from an AI API)
34
- const generatedCode = generateSampleCode(appDescription.value, tech);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  // Display the code with typewriter effect
37
  typeWriterEffect(codeOutput, generatedCode, 10, () => {
@@ -39,14 +57,38 @@ document.addEventListener('DOMContentLoaded', () => {
39
  generateBtn.innerHTML = '<i data-feather="code"></i> Generate My App';
40
  feather.replace();
41
 
42
- // Show the chat section
 
43
  chatSection.classList.remove('hidden');
44
- chatSection.scrollIntoView({ behavior: 'smooth' });
 
 
 
45
  });
46
- }, 2000);
 
 
 
 
 
 
47
  });
48
 
49
- // Chat functionality
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  const chatInput = document.getElementById('chat-input');
51
  const sendChatBtn = document.getElementById('send-chat-btn');
52
  const chatMessages = document.getElementById('chat-messages');
@@ -101,92 +143,7 @@ document.addEventListener('DOMContentLoaded', () => {
101
 
102
  type();
103
  }
104
-
105
- function generateSampleCode(description, tech) {
106
- // This would be replaced with actual AI API call in production
107
- const baseCode = {
108
- 'React': `import React, { useState } from 'react';
109
- import './App.css';
110
-
111
- function App() {
112
- const [count, setCount] = useState(0);
113
-
114
- return (
115
- <div className="App">
116
- <header className="App-header">
117
- <h1>${extractTitle(description)}</h1>
118
- <p>${extractDescription(description)}</p>
119
- <button onClick={() => setCount(count + 1)}>
120
- Clicked {count} times
121
- </button>
122
- </header>
123
- </div>
124
- );
125
- }
126
-
127
- export default App;`,
128
- 'Vue': `<template>
129
- <div id="app">
130
- <h1>${extractTitle(description)}</h1>
131
- <p>${extractDescription(description)}</p>
132
- <button @click="count++">Clicked {{ count }} times</button>
133
- </div>
134
- </template>
135
-
136
- <script>
137
- export default {
138
- name: 'App',
139
- data() {
140
- return {
141
- count: 0
142
- }
143
- }
144
- }
145
- </script>
146
-
147
- <style>
148
- #app {
149
- text-align: center;
150
- }
151
- </style>`,
152
- 'Flutter': `import 'package:flutter/material.dart';
153
-
154
- void main() {
155
- runApp(MyApp());
156
- }
157
-
158
- class MyApp extends StatelessWidget {
159
- @override
160
- Widget build(BuildContext context) {
161
- return MaterialApp(
162
- title: '${extractTitle(description)}',
163
- home: Scaffold(
164
- appBar: AppBar(
165
- title: Text('${extractTitle(description)}'),
166
- ),
167
- body: Center(
168
- child: Column(
169
- mainAxisAlignment: MainAxisAlignment.center,
170
- children: <Widget>[
171
- Text('${extractDescription(description)}'),
172
- SizedBox(height: 20),
173
- ElevatedButton(
174
- onPressed: () {},
175
- child: Text('Click Me'),
176
- ),
177
- ],
178
- ),
179
- ),
180
- ),
181
- );
182
- }
183
- }`
184
- };
185
-
186
- return baseCode[tech] || `// Code generation for ${tech} is not yet supported\n// ${description}`;
187
- }
188
-
189
- function extractTitle(description) {
190
  const firstSentence = description.split('.')[0];
191
  return firstSentence || "My Awesome App";
192
  }
 
8
  choice.classList.add('active');
9
  });
10
  });
 
11
  // Code generation
12
  const generateBtn = document.getElementById('generate-btn');
13
  const appDescription = document.getElementById('app-description');
14
  const codeOutput = document.getElementById('code-output');
15
  const chatSection = document.getElementById('chat');
16
+ const previewSection = document.getElementById('preview');
17
+ const previewFrame = document.getElementById('preview-frame');
18
+ const viewCodeBtn = document.getElementById('view-code-btn');
19
+ const viewPreviewBtn = document.getElementById('view-preview-btn');
20
 
21
  generateBtn.addEventListener('click', async () => {
22
  if (!appDescription.value.trim()) {
 
29
  generateBtn.innerHTML = '<i data-feather="loader" class="animate-spin"></i> Generating...';
30
  feather.replace();
31
 
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://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=YOUR_API_KEY', {
38
+ method: 'POST',
39
+ headers: {
40
+ 'Content-Type': 'application/json',
41
+ },
42
+ body: JSON.stringify({
43
+ contents: [{
44
+ parts: [{
45
+ text: prompt
46
+ }]
47
+ }]
48
+ })
49
+ });
50
+
51
+ const data = await response.json();
52
+ const generatedCode = data.candidates[0].content.parts[0].text;
53
 
54
  // Display the code with typewriter effect
55
  typeWriterEffect(codeOutput, generatedCode, 10, () => {
 
57
  generateBtn.innerHTML = '<i data-feather="code"></i> Generate My App';
58
  feather.replace();
59
 
60
+ // Show preview and chat sections
61
+ previewSection.classList.remove('hidden');
62
  chatSection.classList.remove('hidden');
63
+
64
+ // Update preview iframe
65
+ const blob = new Blob([generatedCode], {type: 'text/html'});
66
+ previewFrame.src = URL.createObjectURL(blob);
67
  });
68
+ } catch (error) {
69
+ console.error('Error generating code:', error);
70
+ alert('Failed to generate code. Please try again.');
71
+ generateBtn.disabled = false;
72
+ generateBtn.innerHTML = '<i data-feather="code"></i> Generate My App';
73
+ feather.replace();
74
+ }
75
  });
76
 
77
+ // Toggle between code and preview
78
+ viewCodeBtn.addEventListener('click', () => {
79
+ codeOutput.style.display = 'block';
80
+ previewFrame.style.display = 'none';
81
+ viewCodeBtn.classList.add('active');
82
+ viewPreviewBtn.classList.remove('active');
83
+ });
84
+
85
+ viewPreviewBtn.addEventListener('click', () => {
86
+ codeOutput.style.display = 'none';
87
+ previewFrame.style.display = 'block';
88
+ viewPreviewBtn.classList.add('active');
89
+ viewCodeBtn.classList.remove('active');
90
+ });
91
+ // Chat functionality
92
  const chatInput = document.getElementById('chat-input');
93
  const sendChatBtn = document.getElementById('send-chat-btn');
94
  const chatMessages = document.getElementById('chat-messages');
 
143
 
144
  type();
145
  }
146
+ function extractTitle(description) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  const firstSentence = description.split('.')[0];
148
  return firstSentence || "My Awesome App";
149
  }
style.css CHANGED
@@ -46,7 +46,17 @@ body {
46
  background-color: #6366f1;
47
  color: white;
48
  }
49
-
50
  .tech-choice:hover:not(.active) {
51
  background-color: #e5e7eb;
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
46
  background-color: #6366f1;
47
  color: white;
48
  }
 
49
  .tech-choice:hover:not(.active) {
50
  background-color: #e5e7eb;
51
+ }
52
+
53
+ /* Preview iframe styles */
54
+ iframe {
55
+ border: none;
56
+ }
57
+
58
+ /* View toggle buttons */
59
+ #view-code-btn.active,
60
+ #view-preview-btn.active {
61
+ color: white;
62
+ }