Spaces:
Sleeping
Sleeping
Yash Worlikar
commited on
Commit
·
cd417d0
1
Parent(s):
ac5d1bb
Fixed error messages
Browse files
Components/Pages/Home.razor
CHANGED
@@ -5,6 +5,7 @@
|
|
5 |
@using Markdig
|
6 |
@using Microsoft.AspNetCore.Components
|
7 |
@using System.Runtime.CompilerServices
|
|
|
8 |
@using Microsoft.SemanticKernel
|
9 |
@rendermode InteractiveServer
|
10 |
|
@@ -59,7 +60,7 @@
|
|
59 |
</div>
|
60 |
<div class="col-md-6">
|
61 |
<label for="OpenAI_ApiKey" class="form-label">API Key</label>
|
62 |
-
<InputText class="form-control" type="password"
|
63 |
</div>
|
64 |
</div>
|
65 |
</div>
|
@@ -98,6 +99,13 @@
|
|
98 |
{
|
99 |
<img src="@ImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 150px;" />
|
100 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
</div>
|
102 |
</div>
|
103 |
</div>
|
@@ -109,7 +117,6 @@
|
|
109 |
{
|
110 |
<div class="d-flex justify-content-center">
|
111 |
<div class="spinner-border text-primary" role="status">
|
112 |
-
<span class="visually-hidden">Loading...</span>
|
113 |
</div>
|
114 |
</div>
|
115 |
}
|
@@ -132,7 +139,6 @@
|
|
132 |
{
|
133 |
<div class="d-flex justify-content-center">
|
134 |
<div class="spinner-border text-primary" role="status">
|
135 |
-
<span class="visually-hidden">Loading...</span>
|
136 |
</div>
|
137 |
</div>
|
138 |
}
|
@@ -208,7 +214,7 @@
|
|
208 |
duplicateSpace = Config.GetValue<string>("HFDuplicateSpace") ?? string.Empty;
|
209 |
if (!_foodCheckerService.IsValid())
|
210 |
{
|
211 |
-
errorMessage = "API keys missing from config
|
212 |
}
|
213 |
}
|
214 |
|
@@ -221,6 +227,8 @@
|
|
221 |
|
222 |
private async Task HandleSelectedFiles(InputFileChangeEventArgs e)
|
223 |
{
|
|
|
|
|
224 |
isUploadingImage = "disabled";
|
225 |
var imageFile = e.File;
|
226 |
await InvokeAsync(() => this.StateHasChanged());
|
@@ -243,7 +251,6 @@
|
|
243 |
}
|
244 |
isUploadingImage = string.Empty;
|
245 |
await InvokeAsync(() => this.StateHasChanged());
|
246 |
-
|
247 |
}
|
248 |
|
249 |
private async Task<ReadOnlyMemory<byte>> ReadFileBytes(IBrowserFile imageFile)
|
@@ -299,17 +306,25 @@
|
|
299 |
}
|
300 |
}
|
301 |
}
|
302 |
-
catch(HttpOperationException hEx)
|
303 |
{
|
304 |
if (hEx.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
|
305 |
{
|
306 |
-
errorMessage =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
}
|
308 |
}
|
309 |
catch (Exception ex)
|
310 |
{
|
311 |
Console.WriteLine(ex.Message);
|
312 |
-
errorMessage =
|
313 |
}
|
314 |
finally
|
315 |
{
|
|
|
5 |
@using Markdig
|
6 |
@using Microsoft.AspNetCore.Components
|
7 |
@using System.Runtime.CompilerServices
|
8 |
+
@using System.Text.Json
|
9 |
@using Microsoft.SemanticKernel
|
10 |
@rendermode InteractiveServer
|
11 |
|
|
|
60 |
</div>
|
61 |
<div class="col-md-6">
|
62 |
<label for="OpenAI_ApiKey" class="form-label">API Key</label>
|
63 |
+
<InputText class="form-control" type="password" id="OpenAI_ApiKey" @bind-Value="temporaryConfig.OpenAI_ApiKey" placeholder="Enter API Key" />
|
64 |
</div>
|
65 |
</div>
|
66 |
</div>
|
|
|
99 |
{
|
100 |
<img src="@ImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 150px;" />
|
101 |
}
|
102 |
+
else if (!string.IsNullOrWhiteSpace(isUploadingImage))
|
103 |
+
{
|
104 |
+
<div class="d-flex justify-content-center">
|
105 |
+
<div class="spinner-border text-primary" role="status">
|
106 |
+
</div>
|
107 |
+
</div>
|
108 |
+
}
|
109 |
</div>
|
110 |
</div>
|
111 |
</div>
|
|
|
117 |
{
|
118 |
<div class="d-flex justify-content-center">
|
119 |
<div class="spinner-border text-primary" role="status">
|
|
|
120 |
</div>
|
121 |
</div>
|
122 |
}
|
|
|
139 |
{
|
140 |
<div class="d-flex justify-content-center">
|
141 |
<div class="spinner-border text-primary" role="status">
|
|
|
142 |
</div>
|
143 |
</div>
|
144 |
}
|
|
|
214 |
duplicateSpace = Config.GetValue<string>("HFDuplicateSpace") ?? string.Empty;
|
215 |
if (!_foodCheckerService.IsValid())
|
216 |
{
|
217 |
+
errorMessage = "API keys missing from config";
|
218 |
}
|
219 |
}
|
220 |
|
|
|
227 |
|
228 |
private async Task HandleSelectedFiles(InputFileChangeEventArgs e)
|
229 |
{
|
230 |
+
ImageUrl = string.Empty;
|
231 |
+
errorMessage = string.Empty;
|
232 |
isUploadingImage = "disabled";
|
233 |
var imageFile = e.File;
|
234 |
await InvokeAsync(() => this.StateHasChanged());
|
|
|
251 |
}
|
252 |
isUploadingImage = string.Empty;
|
253 |
await InvokeAsync(() => this.StateHasChanged());
|
|
|
254 |
}
|
255 |
|
256 |
private async Task<ReadOnlyMemory<byte>> ReadFileBytes(IBrowserFile imageFile)
|
|
|
306 |
}
|
307 |
}
|
308 |
}
|
309 |
+
catch (HttpOperationException hEx)
|
310 |
{
|
311 |
if (hEx.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
|
312 |
{
|
313 |
+
errorMessage = "Rate Limit Exceeded. Please try again Later";
|
314 |
+
}
|
315 |
+
else if (hEx.StatusCode == System.Net.HttpStatusCode.BadRequest)
|
316 |
+
{
|
317 |
+
using JsonDocument doc = JsonDocument.Parse(hEx.ResponseContent);
|
318 |
+
JsonElement root = doc.RootElement;
|
319 |
+
string message = root.GetProperty("error").GetProperty("message").GetString();
|
320 |
+
Console.WriteLine(message);
|
321 |
+
errorMessage = message;
|
322 |
}
|
323 |
}
|
324 |
catch (Exception ex)
|
325 |
{
|
326 |
Console.WriteLine(ex.Message);
|
327 |
+
errorMessage = "Error: An unexpected error has occurred";
|
328 |
}
|
329 |
finally
|
330 |
{
|
SemanticKernel/Plugins/FoodCheckerPlugin.cs
CHANGED
@@ -58,7 +58,7 @@ namespace FoodHealthChecker.SemanticKernel.Plugins
|
|
58 |
}
|
59 |
public static class FoodCheckerTemplates
|
60 |
{
|
61 |
-
public const string SystemMessage = @"You are
|
62 |
|
63 |
public const string CheckFoodHealth =
|
64 |
@"
|
@@ -70,6 +70,7 @@ Also list any cancer causing or harmful substances if present.
|
|
70 |
[RESPONSE]
|
71 |
**Predicted Rating**
|
72 |
**Reasoning**
|
|
|
73 |
";
|
74 |
|
75 |
public const string GetIngredients =
|
|
|
58 |
}
|
59 |
public static class FoodCheckerTemplates
|
60 |
{
|
61 |
+
public const string SystemMessage = @"You are an AI Food expert with extensive knowledge in Nutrion";
|
62 |
|
63 |
public const string CheckFoodHealth =
|
64 |
@"
|
|
|
70 |
[RESPONSE]
|
71 |
**Predicted Rating**
|
72 |
**Reasoning**
|
73 |
+
**Harmful substances**
|
74 |
";
|
75 |
|
76 |
public const string GetIngredients =
|