-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
177 lines (165 loc) · 8.78 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FIT.AI</title>
<link rel="icon" href="#">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:[email protected]&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/footer.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.3/html2pdf.bundle.min.js"></script>
</head>
<body>
<iframe src="https://justrals.github.io/justrals-embed" width="100%" height="50px" style="border:none; z-index: 1000; position: fixed;" allowtransparency="true"></iframe><style>header {margin-top:50px;}</style>
<header>
<div class="container">
<div class="header-wrapper">
<a href="index.html"><p class="logo">FIT.AI</p></a>
<ul class="nav">
<li class="nav-item">
<div class="dropdown">
<button class="dropbtn">Username</button>
<div class="dropdown-content" id="dropdownMenu">
<a href="index.html">Dashboard</a>
<a href="index.html">Settings</a>
<a href="index.html">Log out</a>
</div>
</div>
</li>
</ul>
</div>
</div>
</header>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
const dropbtn = document.querySelector('.dropbtn');
const dropdownContent = document.getElementById('dropdownMenu');
dropbtn.addEventListener('click', () => {
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
window.addEventListener('click', (event) => {
if (!event.target.matches('.dropbtn')) {
if (dropdownContent.style.display === 'block') {
dropdownContent.style.display = 'none';
}
}
});
});
</script>
<main>
<div class="container">
<h1 class="title">Make fitness plan</h1>
<div class="hero-dashboard">
<div class="left">
<form id="fitness-form">
<div class="input">
<p class="input-badge">Age</p>
<input type="number" id="age" name="age" min="0" max="100" required>
</div>
<div class="input">
<p class="input-badge">Weight (kg)</p>
<input type="number" id="weight" name="weight" min="20" max="300" required>
</div>
<div class="input">
<p class="input-badge">Height (cm)</p>
<input type="number" id="height" name="height" min="50" max="300" required>
</div>
<div class="input">
<p class="input-badge">Sex</p>
<select name="sex" id="sex" required><option value="" disabled selected> </option><option value="male">Male</option><option value="woman">Woman</option></select>
</div>
<div class="input">
<p class="input-badge">Language</p>
<input type="text" id="language" name="language" required>
</div>
<div class="input">
<p class="input-badge">Gemini API Token</p>
<input type="text" id="token" name="token" required>
</div>
<button id="submit" type="submit" class="button button--light">Generate Fitness Plan</button>
</form>
</div>
<div id="output-box" class="right">
<div id="output"></div>
<div id="loader" class="loader-wrapper">
<div class="loader"></div>
</div>
</div>
</div>
</div>
</main>
<footer>
<div class="container">
<div class="header-wrapper">
<a href="index.html"><p class="logo">FIT.AI</p></a>
</div>
</div>
</footer>
<script type="importmap">
{
"imports": {
"@google/generative-ai": "https://esm.sh/@google/generative-ai"
}
}
</script>
<script type="module">
import { GoogleGenerativeAI } from "@google/generative-ai";
const loader = document.getElementById('loader');
const outputbox = document.getElementById('output-box')
const submitButton = document.getElementById('submit');
let savePdfButton;
async function savePDF() {
const API_KEY = document.getElementById('token').value;
const genAI = new GoogleGenerativeAI(API_KEY);
const age = document.getElementById('age').value;
const weight = document.getElementById('weight').value;
const height = document.getElementById('height').value;
const sex = document.getElementById('sex').value;
const language = document.getElementById('language').value;
const prompt = `Generate a fitness plan in ${language} language for a person with the following details:\nAge: ${age},\nWeight: ${weight} kg,\nHeight: ${height} cm,\nSex: ${sex}. Make the outputs in html format with tags and don't write "html" at the beginning.`;
try {
outputbox.classList.remove('right-error');
document.getElementById('output').innerHTML = '';
loader.classList.add('active');
submitButton.disabled = true;
const model = await genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const result = await model.generateContent(prompt);
if (result && typeof result === 'object') {
const htmlContent = result.response.candidates[0].content.parts[0].text;
document.getElementById('output').innerHTML = htmlContent;
savePdfButton = document.createElement('button');
savePdfButton.id = 'save-pdf';
savePdfButton.classList.add('button', 'button--light');
savePdfButton.textContent = 'Save as PDF';
savePdfButton.addEventListener('click', async function(event) {
event.preventDefault();
await generateAndSavePDF();
});
document.getElementById('output').appendChild(savePdfButton);
} else {
throw new Error("Empty or invalid response received.");
}
} catch (error) {
console.error("Error generating fitness plan:", error);
document.getElementById('output').textContent = `Failed to generate fitness plan. Try refreshing the page and trying again.`;
outputbox.classList.add('right-error');
} finally {
loader.classList.remove('active');
submitButton.disabled = false;
}
}
async function generateAndSavePDF() {
const element = document.getElementById('output');
await html2pdf().from(element).save('fitness_plan.pdf');
}
document.getElementById('fitness-form').addEventListener('submit', async function(event) {
event.preventDefault();
await savePDF();
});
</script>
</body>
</html>