-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBasic.html
346 lines (303 loc) · 13.1 KB
/
Basic.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project Suggestion System</title>
<script src="https://cdn.jsdelivr.net/npm/@google/[email protected]/dist/index.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 800px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1, h2 {
color: #333;
}
.progress-bar {
width: 100%;
background-color: #e0e0e0;
padding: 3px;
border-radius: 3px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2);
margin-bottom: 20px;
}
.progress-bar-fill {
display: block;
height: 22px;
background-color: #659cef;
border-radius: 3px;
transition: width 500ms ease-in-out;
}
.section {
display: none;
}
.section.active {
display: block;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"], select, textarea {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
.radio-group {
margin-bottom: 10px;
}
.radio-group label {
display: inline-block;
margin-right: 15px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background-color: #45a049;
}
#factBox, #resultBox {
background-color: #f0f8ff;
border: 1px solid #b0d4ff;
border-radius: 5px;
padding: 10px;
margin-top: 20px;
display: none;
}
#apiKeyBox {
background-color: #f0f8ff;
border: 1px solid #b0d4ff;
border-radius: 5px;
padding: 10px;
margin-bottom: 20px;
text-align: center;
}
#apiKeyError {
color: red;
display: none;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="container">
<div id="apiKeyBox">
<label for="apiKey">Enter Gemini API Key:</label>
<input type="text" id="apiKey" placeholder="Enter your API key here">
<button onclick="setApiKey()">Set Key</button>
<div id="apiKeyError"></div>
</div>
<h1>Project Suggestion System</h1>
<div class="progress-bar">
<span class="progress-bar-fill" style="width: 0%;"></span>
</div>
<div id="factBox"></div>
<form id="projectSuggestionForm">
<div id="section1" class="section active">
<h2>Personal Information</h2>
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" required>
<label for="year">Current Year of Study:</label>
<select id="year" name="year" required>
<option value="">Select Year</option>
<option value="1">1st Year</option>
<option value="2">2nd Year</option>
<option value="3">3rd Year</option>
<option value="4">4th Year</option>
</select>
<label for="university">University:</label>
<input type="text" id="university" name="university" required>
<button type="button" onclick="nextSection(1)">Next</button>
</div>
<div id="section2" class="section">
<h2>Technical Skills</h2>
<p>Rate your proficiency in the following areas:</p>
<div class="radio-group">
<label>Python:</label>
<label><input type="radio" name="python" value="1" required> Beginner</label>
<label><input type="radio" name="python" value="2"> Intermediate</label>
<label><input type="radio" name="python" value="3"> Advanced</label>
</div>
<div class="radio-group">
<label>Java:</label>
<label><input type="radio" name="java" value="1" required> Beginner</label>
<label><input type="radio" name="java" value="2"> Intermediate</label>
<label><input type="radio" name="java" value="3"> Advanced</label>
</div>
<div class="radio-group">
<label>Web Development:</label>
<label><input type="radio" name="webdev" value="1" required> Beginner</label>
<label><input type="radio" name="webdev" value="2"> Intermediate</label>
<label><input type="radio" name="webdev" value="3"> Advanced</label>
</div>
<div class="radio-group">
<label>Machine Learning:</label>
<label><input type="radio" name="ml" value="1" required> Beginner</label>
<label><input type="radio" name="ml" value="2"> Intermediate</label>
<label><input type="radio" name="ml" value="3"> Advanced</label>
</div>
<button type="button" onclick="prevSection(2)">Previous</button>
<button type="button" onclick="nextSection(2)">Next</button>
</div>
<div id="section3" class="section">
<h2>Project Preferences</h2>
<label>Preferred project type:</label>
<div class="radio-group">
<label><input type="radio" name="projectType" value="individual" required> Individual</label>
<label><input type="radio" name="projectType" value="group"> Group</label>
</div>
<label for="projectArea">Preferred project area:</label>
<select id="projectArea" name="projectArea" required>
<option value="">Select Area</option>
<option value="ai">Artificial Intelligence</option>
<option value="webApp">Web Application</option>
<option value="mobile">Mobile App Development</option>
<option value="dataScience">Data Science</option>
<option value="security">Cybersecurity</option>
</select>
<label for="projectDescription">Briefly describe your ideal project:</label>
<textarea id="projectDescription" name="projectDescription" rows="4" required></textarea>
<button type="button" onclick="prevSection(3)">Previous</button>
<button type="submit">Submit</button>
</div>
</form>
<div id="resultBox"></div>
<button id="exportButton" style="display: none;" onclick="exportResults()">Export Results</button>
</div>
</div>
<script>
let apiKey = '';
async function setApiKey() {
const inputKey = document.getElementById('apiKey').value.trim();
if (!inputKey) {
showApiKeyError("Please enter an API key.");
return;
}
try {
const genAI = new GoogleGenerativeAI(inputKey);
const model = genAI.getGenerativeModel({ model: "gemini-1.0-pro" });
// Attempt to generate a simple response to validate the key
await model.generateContent("Hello");
// If we reach here, the key is valid
apiKey = inputKey;
document.getElementById('apiKeyBox').style.display = 'none';
alert('API Key set successfully!');
} catch (error) {
showApiKeyError("Invalid API key. Please try again.");
console.error('API Key validation error:', error);
}
}
function showApiKeyError(message) {
const errorDiv = document.getElementById('apiKeyError');
errorDiv.textContent = message;
errorDiv.style.display = 'block';
}
const totalSections = 3;
let currentSection = 1;
let projectSuggestions = '';
function saveApiKey() {
apiKey = document.getElementById('apiKey').value;
alert('API Key saved!');
}
function updateProgressBar() {
const progress = (currentSection - 1) / totalSections * 100;
document.querySelector('.progress-bar-fill').style.width = `${progress}%`;
}
function showSection(sectionNumber) {
document.querySelectorAll('.section').forEach(section => {
section.classList.remove('active');
});
document.getElementById(`section${sectionNumber}`).classList.add('active');
currentSection = sectionNumber;
updateProgressBar();
}
async function nextSection(current) {
if (current < totalSections) {
await displayFact(current);
showSection(current + 1);
}
}
function prevSection(current) {
if (current > 1) {
showSection(current - 1);
}
}
async function displayFact(sectionNumber) {
const fact = await getFact(sectionNumber);
const factBox = document.getElementById('factBox');
factBox.textContent = fact;
factBox.style.display = 'block';
setTimeout(() => {
factBox.style.display = 'none';
}, 5000);
}
async function getFact(sectionNumber) {
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: "gemini-1.0-pro" });
const prompt = `Generate a fun fact or joke related to section ${sectionNumber} of a project suggestion form for computer science students.`;
try {
const result = await model.generateContent(prompt);
return result.response.text();
} catch (error) {
console.error('Error fetching fact:', error);
return "Oops! I couldn't come up with a fact right now. Let's continue with the form!";
}
}
async function generateProjectSuggestions(formData) {
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: "gemini-1.0-pro" });
const prompt = `You are an expert and experienced project suggestion system. Based on the following student information, suggest different projects. Provide details like project name, description, and tech stack:
${JSON.stringify(formData, null, 2)}
Please suggest 3 different projects suitable for this student.`;
try {
const result = await model.generateContent(prompt);
return result.response.text();
} catch (error) {
console.error('Error generating project suggestions:', error);
return "Sorry, I couldn't generate project suggestions at this time. Please try again later.";
}
}
document.getElementById('projectSuggestionForm').addEventListener('submit', async function(e) {
e.preventDefault();
const formData = new FormData(e.target);
const formObject = Object.fromEntries(formData.entries());
const resultBox = document.getElementById('resultBox');
resultBox.textContent = 'Generating project suggestions...';
resultBox.style.display = 'block';
projectSuggestions = await generateProjectSuggestions(formObject);
resultBox.textContent = projectSuggestions;
document.getElementById('exportButton').style.display = 'block';
});
function exportResults() {
const blob = new Blob([projectSuggestions], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'project_suggestions.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
</script>
</body>
</html>