-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
166 lines (141 loc) · 5.49 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
text-align: center;
font-family: 'Arial', sans-serif;
margin: 20px;
background: linear-gradient(to bottom, #84bada, #ececec);
color: #142d4c;
}
h1 {
color: #3498db;
}
/* Apply the specified colors for buttons */
.choose-file-btn,
.file_submit {
background-color: #9fd3c7;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 8px;
font-size: 20px;
cursor: pointer;
margin: 10px;
display: inline-block;
}
.choose-file-btn:hover,
.file_submit:hover {
background-color: #385170;
}
/* Apply styles to dropdowns */
select {
padding: 10px;
font-size: 16px;
border-radius: 8px;
}
/* Style for the image preview */
#preview-img {
display: none;
}
/* Style for recommendations paragraph */
#myParagraph {
display: none;
color: #385170;
font-size: 18px;
}
</style>
</head>
<body>
<h1>Nutrient Analyzer</h1>
<form class="grid" action="/result" method="POST" enctype="multipart/form-data" onsubmit="submitForm()">
<label for="usernameame">Enter your Name:</label>
<input type="text" id="" name="username"><br><br>
<label for="Height">Enter your height (in cm):</label>
<input type="number" id="" name="height"><br><br>
<label for="Weight">Enter your weight (in kg):</label>
<input type="number" id="" name="weight"><br><br>
<label for="age">Enter your age :</label>
<input type="number" id="" name="age"><br><br>
<label for="gender">Choose your gender:</label>
<select name="gender" id="">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
<label for="activity">Choose your activity lifestile:</label>
<select name="activity" id="">
<option value="1.2">Sedentary (Little to no exercise)</option>
<option value="1.3">Light Exercise (1-3 days per week)</option>
<option value="1.5">Moderate exercise (3-5 days per week)</option>
<option value="1.7">Heavy Exercise (6-7 days per week)</option>
</select>
<label for="serving">Enter number of servings:</label>
<input type="text" id="" name="serving"><br><br>
<label for="fileInput" class="choose-file-btn">Choose File</label>
<input type="file" id="fileInput" accept="image/*" onchange="saveImage()">
<!-- Include the onchange attribute to trigger saveImage when a file is selected -->
{% if name %}
<center>
<h3 style="color: blue;" class="let_space">The dish is {{name}}</h3>
<a href="/table" target="_blank">View your history</a>
<button type="button" onclick="toggleParagraph()">View your recommendations</button>
<p id="myParagraph" style="display:none;">Your recommendations are {{recommendation}}</p>
</center>
{% endif %}
<!-- {% if result %}
<center>
{{result}}
</center>
{% endif %} -->
<center>
<input class="file_submit" type="submit" value="Submit">
</center>
</form>
<!-- Image Preview -->
<img id="preview-img" style="display: none;" alt="Image Preview">
<script>
function toggleParagraph() {
var paragraph = document.getElementById("myParagraph");
if (paragraph.style.display === "none") {
paragraph.style.display = "block";
} else {
paragraph.style.display = "none";
}
}
function saveImage() {
const input = document.getElementById('fileInput');
if (!input || !input.files || !input.files[0]) {
// alert('Please select a file');
return;
}
const file = input.files[0];
const url = URL.createObjectURL(file);
// Show image preview
document.getElementById('preview-img').src = url;
document.getElementById('preview-img').style.display = 'block';
}
function submitForm() {
saveImage(); // Ensure the image is saved before submitting the form
downloadImage(); // Download the image
}
function downloadImage() {
const previewImg = document.getElementById('preview-img');
if (previewImg.src && previewImg.src !== 'about:blank') {
const a = document.createElement('a');
a.href = previewImg.src;
a.download = 'image.jpeg';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
// alert('Please select an image first.');
}
}
</script>
<br>
<br>
<br>
</body>
</html>