Karusell auf ai art seite gefixrt
This commit is contained in:
parent
d8726fbc59
commit
3406748c66
|
@ -0,0 +1,23 @@
|
|||
namespace KIKunstKirstenKlöckner.Extensions
|
||||
{
|
||||
public static class ListExtension
|
||||
{
|
||||
public static IEnumerable<T> PickRandom<T>(this List<T> list, int n)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("List cannot be emtpy: ", nameof(list));
|
||||
}
|
||||
if (n <= 0)
|
||||
{
|
||||
throw new ArgumentException("n must be greater than 0: ", nameof(n));
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int index = Random.Shared.Next(list.Count);
|
||||
yield return list[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
@using DataAccess.Data
|
||||
@using DataAccess.Models
|
||||
@using KIKunstKirstenKlöckner.Data
|
||||
@using KIKunstKirstenKlöckner.Extensions
|
||||
@using System.Diagnostics
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
@ -74,15 +75,18 @@
|
|||
{
|
||||
<div class="carousel-item active">
|
||||
<div class="img-box">
|
||||
<img src="@bildInfo.Dateiname" alt="" />
|
||||
<img src="@bildInfo.Dateiname"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="carousel-item">
|
||||
<div class="img-box">
|
||||
<img src="@bildInfo.Dateiname" alt=""/>
|
||||
<img src="@bildInfo.Dateiname"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
_indexForCarusell++;
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +286,7 @@
|
|||
await GenerateImagesAsync();
|
||||
}
|
||||
|
||||
List<BildInfoModel>? _allBildInfos;
|
||||
IEnumerable<BildInfoModel>? _allBildInfos;
|
||||
|
||||
/// <summary>
|
||||
/// Wenn <see langword="true"/> wird GPT4 verwendet um die Idee zu interpretieren.
|
||||
|
@ -365,8 +369,8 @@
|
|||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_allBildInfos = (await BildInfoData.GetAllBildInfosAsync()).ToList();
|
||||
StateHasChanged();
|
||||
_allBildInfos = (await BildInfoData.GetAllBildInfosAsync()).ToList().PickRandom(10);
|
||||
//await InvokeAsync(StateHasChanged);
|
||||
|
||||
_openAiApiKey = Config.GetValue<string>("API:OpenAI");
|
||||
|
||||
|
|
Loading…
Reference in New Issue