Spaces:
Sleeping
Sleeping
Yash Worlikar
commited on
Commit
·
cca2c82
1
Parent(s):
cd417d0
Updates
Browse files- Components/Pages/Home.razor +43 -28
- FoodCheckerService.cs +2 -2
- Models/TemporaryConfig.cs +1 -3
- SemanticKernel/Plugins/FoodCheckerPlugin.cs +1 -1
Components/Pages/Home.razor
CHANGED
@@ -19,8 +19,11 @@
|
|
19 |
<div class="d-flex justify-content-between gap-2">
|
20 |
<h3 class="card-title mb-2 fw-bold text-start">AI Food Health Checker</h3>
|
21 |
<div>
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
</div>
|
25 |
</div>
|
26 |
|
@@ -83,7 +86,11 @@
|
|
83 |
<div class="col-xl-4">
|
84 |
<div class="card common-card-height">
|
85 |
<div class="card-body">
|
86 |
-
<h4 class="card-title fw-bold
|
|
|
|
|
|
|
|
|
87 |
<div class="form-group mb-3">
|
88 |
<!-- HTML -->
|
89 |
<label for="upload-image" class="custom-upload-button btn btn-primary @isUploadingImage">
|
@@ -95,7 +102,11 @@
|
|
95 |
<button class="btn btn-primary w-100" @onclick="CheckHealth" disabled="@(isProcessingResponse || isProcessingIngredients)">Check Health</button>
|
96 |
</div>
|
97 |
|
98 |
-
@if (!string.IsNullOrWhiteSpace(
|
|
|
|
|
|
|
|
|
99 |
{
|
100 |
<img src="@ImageUrl" alt="Preview Image" class="img-fluid rounded" style="max-height: 150px;" />
|
101 |
}
|
@@ -159,17 +170,41 @@
|
|
159 |
|
160 |
@code {
|
161 |
public TemporaryConfig temporaryConfig { get; set; } = new TemporaryConfig();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
private bool isPopupVisible = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
private async Task OpenModal()
|
164 |
{
|
165 |
isPopupVisible = true;
|
166 |
-
StateHasChanged();
|
167 |
}
|
168 |
|
169 |
private async Task CloseModal()
|
170 |
{
|
171 |
isPopupVisible = false;
|
172 |
-
StateHasChanged();
|
173 |
}
|
174 |
|
175 |
private async Task SubmitForm()
|
@@ -192,22 +227,7 @@
|
|
192 |
}
|
193 |
await CloseModal();
|
194 |
}
|
195 |
-
public string ImageUrl { get; set; } = string.Empty;
|
196 |
-
public ReadOnlyMemory<byte> ImageData { get; set; }
|
197 |
-
public string ImageName { get; set; } = string.Empty;
|
198 |
-
|
199 |
-
public string Ingredients { get; set; } = string.Empty;
|
200 |
-
public string Result { get; set; } = string.Empty;
|
201 |
-
public string duplicateSpace { get; set; } = string.Empty;
|
202 |
|
203 |
-
[Inject]
|
204 |
-
public MarkdownPipeline pipeline { get; set; } = default!;
|
205 |
-
[Inject]
|
206 |
-
public FoodCheckerService _foodCheckerService { get; set; } = default!;
|
207 |
-
[Inject]
|
208 |
-
private NavigationManager Navigation { get; set; } = default!;
|
209 |
-
[Inject]
|
210 |
-
private IConfiguration Config { get; set; } = default;
|
211 |
|
212 |
protected override void OnInitialized()
|
213 |
{
|
@@ -218,12 +238,6 @@
|
|
218 |
}
|
219 |
}
|
220 |
|
221 |
-
private bool isProcessingIngredients = false;
|
222 |
-
private bool isProcessingResponse = false;
|
223 |
-
private string isUploadingImage = string.Empty;
|
224 |
-
private string errorMessage = string.Empty;
|
225 |
-
private CancellationTokenSource _cts = new CancellationTokenSource();
|
226 |
-
|
227 |
|
228 |
private async Task HandleSelectedFiles(InputFileChangeEventArgs e)
|
229 |
{
|
@@ -279,7 +293,8 @@
|
|
279 |
}
|
280 |
try
|
281 |
{
|
282 |
-
|
|
|
283 |
{
|
284 |
isProcessingIngredients = false;
|
285 |
Ingredients += response;
|
|
|
19 |
<div class="d-flex justify-content-between gap-2">
|
20 |
<h3 class="card-title mb-2 fw-bold text-start">AI Food Health Checker</h3>
|
21 |
<div>
|
22 |
+
@if (!string.IsNullOrEmpty(duplicateSpace))
|
23 |
+
{
|
24 |
+
<a class="card-title mb-2 fw-bold btn btn-dark" href="@duplicateSpace" target="_blank">Duplicate this space</a>
|
25 |
+
}
|
26 |
+
<button @onclick="OpenModal" class="card-title mb-2 fw-bold btn btn-dark">Add Temporary Config</button>
|
27 |
</div>
|
28 |
</div>
|
29 |
|
|
|
86 |
<div class="col-xl-4">
|
87 |
<div class="card common-card-height">
|
88 |
<div class="card-body">
|
89 |
+
<h4 class="card-title fw-bold text-start">Add/Upload Image </h4>
|
90 |
+
<div class="form-group mb-3">
|
91 |
+
<InputText class="form-control" @bind-Value="HostedImageUrl" id="hostedimageUrl" placeholder="Hosted Image URL" />
|
92 |
+
</div>
|
93 |
+
|
94 |
<div class="form-group mb-3">
|
95 |
<!-- HTML -->
|
96 |
<label for="upload-image" class="custom-upload-button btn btn-primary @isUploadingImage">
|
|
|
102 |
<button class="btn btn-primary w-100" @onclick="CheckHealth" disabled="@(isProcessingResponse || isProcessingIngredients)">Check Health</button>
|
103 |
</div>
|
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 |
}
|
|
|
170 |
|
171 |
@code {
|
172 |
public TemporaryConfig temporaryConfig { get; set; } = new TemporaryConfig();
|
173 |
+
|
174 |
+
public string HostedImageUrl { get; set; } = string.Empty;
|
175 |
+
public string ImageUrl { get; set; } = string.Empty;
|
176 |
+
public ReadOnlyMemory<byte> ImageData { get; set; }
|
177 |
+
public string ImageName { get; set; } = string.Empty;
|
178 |
+
public string Ingredients { get; set; } = string.Empty;
|
179 |
+
public string Result { get; set; } = string.Empty;
|
180 |
+
|
181 |
+
[Inject]
|
182 |
+
public MarkdownPipeline pipeline { get; set; } = default!;
|
183 |
+
[Inject]
|
184 |
+
public FoodCheckerService _foodCheckerService { get; set; } = default!;
|
185 |
+
[Inject]
|
186 |
+
private NavigationManager Navigation { get; set; } = default!;
|
187 |
+
[Inject]
|
188 |
+
private IConfiguration Config { get; set; } = default!;
|
189 |
+
|
190 |
private bool isPopupVisible = false;
|
191 |
+
private bool isProcessingIngredients = false;
|
192 |
+
private bool isProcessingResponse = false;
|
193 |
+
private string isUploadingImage = string.Empty;
|
194 |
+
private string errorMessage = string.Empty;
|
195 |
+
private string duplicateSpace = string.Empty;
|
196 |
+
private CancellationTokenSource _cts = new CancellationTokenSource();
|
197 |
+
|
198 |
private async Task OpenModal()
|
199 |
{
|
200 |
isPopupVisible = true;
|
201 |
+
await InvokeAsync(() => this.StateHasChanged());
|
202 |
}
|
203 |
|
204 |
private async Task CloseModal()
|
205 |
{
|
206 |
isPopupVisible = false;
|
207 |
+
await InvokeAsync(() => this.StateHasChanged());
|
208 |
}
|
209 |
|
210 |
private async Task SubmitForm()
|
|
|
227 |
}
|
228 |
await CloseModal();
|
229 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
protected override void OnInitialized()
|
233 |
{
|
|
|
238 |
}
|
239 |
}
|
240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
private async Task HandleSelectedFiles(InputFileChangeEventArgs e)
|
243 |
{
|
|
|
293 |
}
|
294 |
try
|
295 |
{
|
296 |
+
string selectedImgUrl = !string.IsNullOrWhiteSpace(HostedImageUrl) ? HostedImageUrl : ImageUrl;
|
297 |
+
await foreach (var response in _foodCheckerService.GetIngredirentsAsync(selectedImgUrl, _cts.Token))
|
298 |
{
|
299 |
isProcessingIngredients = false;
|
300 |
Ingredients += response;
|
FoodCheckerService.cs
CHANGED
@@ -7,7 +7,7 @@ namespace FoodHealthChecker
|
|
7 |
{
|
8 |
public class FoodCheckerService
|
9 |
{
|
10 |
-
private
|
11 |
private bool isValid = false;
|
12 |
private readonly FoodCheckerPlugin _foodCheckerPlugin;
|
13 |
public FoodCheckerService(IConfiguration config, FoodCheckerPlugin foodCheckerPlugin)
|
@@ -47,7 +47,7 @@ namespace FoodHealthChecker
|
|
47 |
}
|
48 |
else if (config.isOpenAIConfigValid())
|
49 |
{
|
50 |
-
kernelBuilder.AddOpenAIChatCompletion(config.OpenAI_ModelId,config.OpenAI_ApiKey);
|
51 |
isValid = true;
|
52 |
}
|
53 |
var kernel = kernelBuilder.Build();
|
|
|
7 |
{
|
8 |
public class FoodCheckerService
|
9 |
{
|
10 |
+
private Kernel _kernel;
|
11 |
private bool isValid = false;
|
12 |
private readonly FoodCheckerPlugin _foodCheckerPlugin;
|
13 |
public FoodCheckerService(IConfiguration config, FoodCheckerPlugin foodCheckerPlugin)
|
|
|
47 |
}
|
48 |
else if (config.isOpenAIConfigValid())
|
49 |
{
|
50 |
+
kernelBuilder.AddOpenAIChatCompletion(config.OpenAI_ModelId, config.OpenAI_ApiKey);
|
51 |
isValid = true;
|
52 |
}
|
53 |
var kernel = kernelBuilder.Build();
|
Models/TemporaryConfig.cs
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
namespace FoodHealthChecker.Models
|
4 |
{
|
5 |
|
6 |
public class TemporaryConfig
|
|
|
1 |
+
namespace FoodHealthChecker.Models
|
|
|
|
|
2 |
{
|
3 |
|
4 |
public class TemporaryConfig
|
SemanticKernel/Plugins/FoodCheckerPlugin.cs
CHANGED
@@ -47,7 +47,7 @@ namespace FoodHealthChecker.SemanticKernel.Plugins
|
|
47 |
{
|
48 |
new TextContent(FoodCheckerTemplates.GetIngredients),
|
49 |
new ImageContent(new Uri(input,UriKind.Absolute))
|
50 |
-
});
|
51 |
await foreach (var result in chatService.GetStreamingChatMessageContentsAsync(chat, s_settings, kernel, cancellationToken))
|
52 |
{
|
53 |
var generatedText = result?.ToString() ?? string.Empty;
|
|
|
47 |
{
|
48 |
new TextContent(FoodCheckerTemplates.GetIngredients),
|
49 |
new ImageContent(new Uri(input,UriKind.Absolute))
|
50 |
+
});
|
51 |
await foreach (var result in chatService.GetStreamingChatMessageContentsAsync(chat, s_settings, kernel, cancellationToken))
|
52 |
{
|
53 |
var generatedText = result?.ToString() ?? string.Empty;
|