Yash Worlikar commited on
Commit
8f9b0d0
·
1 Parent(s): 46165c0

Added hardcodded examples

Browse files
Components/Pages/Home.razor CHANGED
@@ -8,6 +8,8 @@
8
  @using System.Text.Json
9
  @using Microsoft.SemanticKernel
10
  @rendermode InteractiveServer
 
 
11
 
12
  @implements IDisposable
13
  <PageTitle> Food Health Checker</PageTitle>
@@ -104,11 +106,11 @@
104
 
105
  @if (!string.IsNullOrWhiteSpace(HostedImageUrl))
106
  {
107
- <img src="@HostedImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 150px;" />
108
  }
109
  else if (!string.IsNullOrWhiteSpace(ImageUrl))
110
  {
111
- <img src="@ImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 150px;" />
112
  }
113
  else if (!string.IsNullOrWhiteSpace(isUploadingImage))
114
  {
@@ -166,9 +168,95 @@
166
  </div>
167
  </div>
168
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  @code {
 
 
172
  public TemporaryConfig temporaryConfig { get; set; } = new TemporaryConfig();
173
 
174
  public string HostedImageUrl { get; set; } = string.Empty;
@@ -252,7 +340,7 @@
252
  var folderPath = Path.Combine("wwwroot", "temp");
253
  if (Directory.Exists(folderPath))
254
  {
255
- // Delete existing images
256
  Array.ForEach(Directory.GetFiles(folderPath), File.Delete);
257
  }
258
  else
@@ -301,7 +389,7 @@
301
  Ingredients = string.Empty;
302
  await InvokeAsync(() => this.StateHasChanged());
303
 
304
- if (!Uri.IsWellFormedUriString(ImageUrl, UriKind.Absolute))
305
  {
306
  errorMessage = "Invalid URL";
307
  isProcessingIngredients = false;
 
8
  @using System.Text.Json
9
  @using Microsoft.SemanticKernel
10
  @rendermode InteractiveServer
11
+ @inject IJSRuntime JSRuntime
12
+
13
 
14
  @implements IDisposable
15
  <PageTitle> Food Health Checker</PageTitle>
 
106
 
107
  @if (!string.IsNullOrWhiteSpace(HostedImageUrl))
108
  {
109
+ <img src="@HostedImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 120px;" />
110
  }
111
  else if (!string.IsNullOrWhiteSpace(ImageUrl))
112
  {
113
+ <img src="@ImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 120px;" />
114
  }
115
  else if (!string.IsNullOrWhiteSpace(isUploadingImage))
116
  {
 
168
  </div>
169
  </div>
170
  </div>
171
+ <div class="row mt-2">
172
+ <div class="col-xl-12">
173
+ <div class="card">
174
+ <div class="card-body overflow-auto">
175
+ <h3 class="fw-bold text-start">Examples</h3>
176
+ <table class="table custom-table">
177
+ <thead>
178
+ <tr>
179
+ <th>Names</th>
180
+ <th>Images</th>
181
+ <th>See Results</th>
182
+ </tr>
183
+ </thead>
184
+ <tbody>
185
+ @foreach (var example in Examples)
186
+ {
187
+ <tr>
188
+ <td><a href="@example.HostedImageUrl" target="_blank">@example.Name </a></td>
189
+ <td><img src="@example.HostedImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 150px; max-width: 150px" /></td>
190
+ <td>
191
+ <button class="btn btn-primary" @onclick="() => { UpdateExample(example.Name); ScrollToTop(); }">
192
+ See Results
193
+ </button>
194
+ </td>
195
+ </tr>
196
+ }
197
+ </tbody>
198
+ </table>
199
+ </div>
200
+ </div>
201
+ </div>
202
+ </div>
203
  </div>
204
+ <script>
205
+ function scrollToTop() {
206
+ document.documentElement.scrollTop = 0;
207
+ }
208
+ </script>
209
+ @code {
210
+ public class ExamplesInfo
211
+ {
212
+ public string Name { get; set; }
213
+ public string HostedImageUrl { get; set; }
214
+ public string Ingredients { get; set; }
215
+ public string Result { get; set; }
216
+ }
217
+
218
+ public List<ExamplesInfo> Examples = new List<ExamplesInfo>()
219
+ {
220
+ new ExamplesInfo { Name = "Milk chocolate", HostedImageUrl = "https://images.openfoodfacts.org/images/products/762/220/173/0253/ingredients_en.5.full.jpg",
221
+ Ingredients ="**Ingredients**\nMilk Chocolate (Sugar, Milk Solids, Cocoa Butter, Cocoa Mass, Emulsifiers (Soy Lecithin, E476), Flavourings)\n\n**Nutritional Values**\n- Serving Size: 1 bar (approx. 21g)\n- Energy: 110 kcal\n- Protein: 1.3g\n- Carbohydrates: 12.7g\n - Sugars: 12.5g\n- Fat: 6.1g\n - Saturated Fat: 3.7g\n- Fiber: 0.2g\n- Sodium: 20mg",
222
+ Result = "**Predicted Rating**\nUnhealthy\n\n**Reasoning**\nThis product is high in sugar and saturated fat, which can contribute to weight gain and heart problems if consumed in large amounts. It also has very little fiber and protein, making it less nutritious overall.\n\n**Harmful substances**\n- **Sugar**: High sugar content can lead to tooth decay, obesity, and increased risk of type 2 diabetes.\n- **Saturated Fat**: High levels of saturated fat can raise cholesterol levels and increase the risk of heart disease.\n- **Soy Lecithin**: Common allergen for those with soy allergies." },
223
+
224
 
225
+ new ExamplesInfo { Name = "Bacon", HostedImageUrl = "https://images.openfoodfacts.org/images/products/841/048/607/8035/ingredients_es.29.full.jpg",
226
+ Ingredients = "**Ingredients**\nMechanically separated chicken meat, pork fat, water, salt, dextrose, stabilizers (E-466, E-508, E-450), flavors and spices, smoke flavor, antioxidant (E-316), preservative (E-250). May contain traces of soy and milk protein.\n\n**Nutritional Values**\nNot Found",
227
+ Result ="**Predicted Rating**\nVery Unhealthy\n\n**Reasoning**\nThis product contains high amounts of processed meats, fats, and additives like preservatives and stabilizers, which are not good for your health if consumed regularly. It also lacks any nutritional information, making it hard to assess its overall health benefits.\n\n**Harmful substances**\n- E-250 (Sodium Nitrite): Can form cancer-causing compounds called nitrosamines.\n- Mechanically separated meat: Often contains higher levels of fat and may have bone fragments.\n- May contain traces of soy and milk protein: Common allergens." },
228
+
229
+ new ExamplesInfo { Name = "High Protein Chicken & Chorizo Paella", HostedImageUrl = "https://images.openfoodfacts.org/images/products/505/590/422/3289/front_en.3.full.jpg",
230
+ Ingredients ="**Ingredients**\nChicken breast and chorizo pieces in a rich paella sauce with rice, garden peas, semi dried cherry tomatoes and diced red peppers.\n\n**Nutritional Values**\nEnergy: 1919 kJ / 460 kcal\nFat: 20.19g\nSaturated Fat: 4.2g\nSugar: 6.8g\nSalt: 1.799g",
231
+ Result = "**Predicted Rating**\nModerately Healthy\n\n**Reasoning**\nThis dish contains a good mix of protein from chicken breast and chorizo, along with vegetables like peas, tomatoes, and peppers. However, it has a relatively high fat content, especially saturated fat, and a significant amount of salt, which can be concerning if consumed in large quantities.\n\n**Harmful substances**\n- Salt: High salt content can lead to high blood pressure and other cardiovascular issues if consumed excessively.\n- Saturated Fat: High levels of saturated fat can increase the risk of heart disease." },
232
+
233
+ new ExamplesInfo { Name = "Whole Milk", HostedImageUrl = "https://images.openfoodfacts.org/images/products/501/226/200/4011/ingredients_en.8.full.jpg",
234
+ Ingredients = "**Ingredients**\nWhole milk (60%), whipping cream (21%), sugar, milk solids, glycerine, emulsifier (mono- and diglycerides of fatty acids), pasteurised free range eggs, stabilisers (sodium alginate and guar gum).\n\n**Nutritional Values**\nNot Found",
235
+ Result ="**Predicted Rating**\nUnhealthy\n\n**Reasoning**\nThis product is high in whole milk, cream, and sugar, which means it has a lot of fat and sugar, making it unhealthy if consumed in large amounts. The presence of emulsifiers and stabilizers, while not necessarily harmful, indicates processed ingredients.\n\n**Harmful substances**\nNone of the listed ingredients are known allergens or cancer-causing substances, but the high sugar and fat content can contribute to health issues like obesity and heart disease if consumed excessively." },
236
+
237
+ new ExamplesInfo { Name = "Frankfurt sausages", HostedImageUrl = "https://images.openfoodfacts.org/images/products/841/044/800/1002/ingredients_es.9.full.jpg",
238
+ Ingredients = "**Ingredients**\nPork meat 86% (origin Spain), water, salt, spices, stabilizer: di- and polyphosphates, dextrose, antioxidant: ascorbic acid, preservative: sodium nitrite.\n\n**Nutritional Values**\nNot Found",
239
+ Result = "**Predicted Rating**\nUnhealthy\n\n**Reasoning**\nThis product contains a high percentage of pork meat, but it also includes additives like stabilizers, preservatives, and dextrose, which are not ideal for health. Sodium nitrite, in particular, is a preservative that has been linked to health concerns.\n\n**Harmful substances**\n- Sodium nitrite: This preservative can form nitrosamines, which are compounds that have been linked to an increased risk of cancer."}
240
+ };
241
+ private void ScrollToTop()
242
+ {
243
+ JSRuntime.InvokeVoidAsync("scrollToTop");
244
+ }
245
+ private async Task UpdateExample(string key)
246
+ {
247
+ var example = Examples.Find(e => e.Name == key);
248
+ if (example != null)
249
+ {
250
+ HostedImageUrl = example.HostedImageUrl;
251
+ Ingredients = example.Ingredients;
252
+ Result = example.Result;
253
+ }
254
+ await InvokeAsync(() => this.StateHasChanged());
255
+ }
256
+ }
257
  @code {
258
+
259
+
260
  public TemporaryConfig temporaryConfig { get; set; } = new TemporaryConfig();
261
 
262
  public string HostedImageUrl { get; set; } = string.Empty;
 
340
  var folderPath = Path.Combine("wwwroot", "temp");
341
  if (Directory.Exists(folderPath))
342
  {
343
+ // Delete existing images
344
  Array.ForEach(Directory.GetFiles(folderPath), File.Delete);
345
  }
346
  else
 
389
  Ingredients = string.Empty;
390
  await InvokeAsync(() => this.StateHasChanged());
391
 
392
+ if (!Uri.IsWellFormedUriString(ImageUrl, UriKind.Absolute) && !Uri.IsWellFormedUriString(HostedImageUrl, UriKind.Absolute))
393
  {
394
  errorMessage = "Invalid URL";
395
  isProcessingIngredients = false;
SemanticKernel/Plugins/FoodCheckerPlugin.cs CHANGED
@@ -64,7 +64,7 @@ namespace FoodHealthChecker.SemanticKernel.Plugins
64
  @"
65
  [Instruction]
66
  Given the list of ingredients for a food product give it a Rating from Very Unhealthy to very Healthy. Also give the reasoning in ELI5 format using less than 3 sentences in the below response format.
67
- Also list any cancer causing or harmful substances if present.
68
  [Ingredients]
69
  {{$input}}
70
  [RESPONSE]
@@ -76,7 +76,7 @@ Also list any cancer causing or harmful substances if present.
76
  public const string GetIngredients =
77
  @"
78
  [Instruction]
79
- Get the ingredients and nutritional values from the given food product images as briefly as possible in the given format else respond with <|ERROR|> if nothing if found
80
  [RESPONSE]
81
  **Ingredients**
82
  **Nutritional Values**";
 
64
  @"
65
  [Instruction]
66
  Given the list of ingredients for a food product give it a Rating from Very Unhealthy to very Healthy. Also give the reasoning in ELI5 format using less than 3 sentences in the below response format.
67
+ Also list any allergens, cancer causing or harmful substances if present along with exact reason.
68
  [Ingredients]
69
  {{$input}}
70
  [RESPONSE]
 
76
  public const string GetIngredients =
77
  @"
78
  [Instruction]
79
+ Get the ingredients and nutritional values in english from the given food product images as briefly as possible in the given format else respond with <|ERROR|> if nothing if found
80
  [RESPONSE]
81
  **Ingredients**
82
  **Nutritional Values**";
wwwroot/app.css CHANGED
@@ -1,16 +1,5 @@
1
  /* layout-related.css */
2
 
3
- /* Reset some default styles */
4
- body {
5
- margin: 0;
6
- padding: 0;
7
- display: flex;
8
- align-items: flex-start;
9
- justify-content: center;
10
- height: 100vh;
11
- }
12
-
13
-
14
  /* Center the form */
15
  .container {
16
  padding: 15px;
@@ -171,10 +160,9 @@ h1, h2, h3, h4, h5, h6 {
171
  }
172
 
173
  .ai-response {
174
- height: 200px;
175
- overflow-y: auto;
176
- scrollbar-width: thin;
177
- -ms-overflow-style: none;
178
  }
179
 
180
  .ai-response::-webkit-scrollbar,
@@ -191,4 +179,19 @@ h1, h2, h3, h4, h5, h6 {
191
  opacity: 0;
192
  position: absolute;
193
  z-index: -1;
194
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  /* layout-related.css */
2
 
 
 
 
 
 
 
 
 
 
 
 
3
  /* Center the form */
4
  .container {
5
  padding: 15px;
 
160
  }
161
 
162
  .ai-response {
163
+ min-height: 200px;
164
+ height: fit-content;
165
+ height: -moz-max-content;
 
166
  }
167
 
168
  .ai-response::-webkit-scrollbar,
 
179
  opacity: 0;
180
  position: absolute;
181
  z-index: -1;
182
+ }
183
+ .custom-table {
184
+ color: #00695C;
185
+ }
186
+
187
+ .custom-table th {
188
+ color: #004D40;
189
+ }
190
+
191
+ .custom-table a {
192
+ color: #009688;
193
+ }
194
+
195
+ .custom-table img {
196
+ border: 1px solid #26A69A;
197
+ }