Compare commits
4 Commits
ece52b9929
...
91b644501a
Author | SHA1 | Date |
---|---|---|
Simon Lübeß | 91b644501a | |
Simon Lübeß | 08bc1e4baa | |
Simon Lübeß | 82663392dc | |
Simon Lübeß | c5994dfc32 |
|
@ -12,7 +12,7 @@ public class ImageGenerator
|
||||||
|
|
||||||
private readonly IConfiguration _config;
|
private readonly IConfiguration _config;
|
||||||
|
|
||||||
private string ModelName => _config.GetValue<string>("StableDiffusionModel") ?? "No Model Defined";
|
//private string ModelName => _config.GetValue<string>("StableDiffusionModel") ?? "No Model Defined";
|
||||||
|
|
||||||
public ImageGenerator(IConfiguration config, BildInfoData bildInfoData)
|
public ImageGenerator(IConfiguration config, BildInfoData bildInfoData)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ public class ImageGenerator
|
||||||
/// <param name="height">Die höhe des zu generierenden Bildes. <see langword="null"/> für Standardhöhe des Modells</param>
|
/// <param name="height">Die höhe des zu generierenden Bildes. <see langword="null"/> für Standardhöhe des Modells</param>
|
||||||
/// <param name="negativePromt">Begriffe, die explizit nicht generiert werden sollen.</param>
|
/// <param name="negativePromt">Begriffe, die explizit nicht generiert werden sollen.</param>
|
||||||
/// <returns>Die BildInfo des generierten Bildes; oder null, wenn ein Fehler auftrat.</returns>
|
/// <returns>Die BildInfo des generierten Bildes; oder null, wenn ein Fehler auftrat.</returns>
|
||||||
public async Task<BildInfoModel?> GenerateImageAsync(string imagePrompt, WunschInfoModel wunschInfo, int? width = null, int? height = null, string negativePromt = "")
|
public async Task<BildInfoModel?> GenerateImageAsync(string imagePrompt, string modelName, WunschInfoModel wunschInfo, int? width = null, int? height = null, string negativePromt = "")
|
||||||
{
|
{
|
||||||
var postData = new
|
var postData = new
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ public class ImageGenerator
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var inferenceModelUrl = $"https://api-inference.huggingface.co/models/{ModelName}";
|
var inferenceModelUrl = $"https://api-inference.huggingface.co/models/{modelName}";
|
||||||
|
|
||||||
var response = await _client.PostAsync(inferenceModelUrl, content);
|
var response = await _client.PostAsync(inferenceModelUrl, content);
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class ImageGenerator
|
||||||
// Die tatsächliche Url wird in SaveImageStreamAsync gesetzt.
|
// Die tatsächliche Url wird in SaveImageStreamAsync gesetzt.
|
||||||
Dateiname = "PlaceHolder",
|
Dateiname = "PlaceHolder",
|
||||||
Datum = imageDate,
|
Datum = imageDate,
|
||||||
ImageModel = ModelName,
|
ImageModel = modelName,
|
||||||
WunschId = wunschInfo.Id,
|
WunschId = wunschInfo.Id,
|
||||||
Prompt = imagePrompt
|
Prompt = imagePrompt
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="HuggingFace" Version="0.2.3" />
|
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
|
||||||
<PackageReference Include="OpenAI" Version="1.7.2" />
|
<PackageReference Include="OpenAI" Version="1.7.2" />
|
||||||
<PackageReference Include="Radzen.Blazor" Version="4.14.4" />
|
<PackageReference Include="Radzen.Blazor" Version="4.14.4" />
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
@using DataAccess.Data
|
@using DataAccess.Data
|
||||||
@using DataAccess.Models
|
@using DataAccess.Models
|
||||||
@using KIKunstKirstenKlöckner.Data
|
@using KIKunstKirstenKlöckner.Data
|
||||||
|
@using System.Diagnostics
|
||||||
|
|
||||||
@inject IConfiguration Config
|
@inject IConfiguration Config
|
||||||
@inject TooltipService TooltipService
|
@inject TooltipService TooltipService
|
||||||
|
@ -23,8 +24,9 @@
|
||||||
<RadzenStack Orientation="Orientation.Vertical" AlignItems="AlignItems.Center">
|
<RadzenStack Orientation="Orientation.Vertical" AlignItems="AlignItems.Center">
|
||||||
<h1>Wunschbilder von KI nur für dich</h1>
|
<h1>Wunschbilder von KI nur für dich</h1>
|
||||||
<RadzenText TextStyle="TextStyle.H2">Nenne uns deinen Wunsch:</RadzenText>
|
<RadzenText TextStyle="TextStyle.H2">Nenne uns deinen Wunsch:</RadzenText>
|
||||||
<RadzenTextBox @bind-Value=@request Placeholder="Dein Wunsch"/>
|
<RadzenTextBox @bind-Value=@_userIdea Placeholder="Dein Wunsch"/>
|
||||||
|
|
||||||
|
@* Zusätzliche Optionen *@
|
||||||
<RadzenPanel AllowCollapse="true" Style="width: 500px;" Text="Mehr Optionen">
|
<RadzenPanel AllowCollapse="true" Style="width: 500px;" Text="Mehr Optionen">
|
||||||
<ChildContent>
|
<ChildContent>
|
||||||
<RadzenCard class="rz-mt-4">
|
<RadzenCard class="rz-mt-4">
|
||||||
|
@ -42,9 +44,9 @@
|
||||||
AlignItems="AlignItems.Center" Wrap="FlexWrap.Wrap">
|
AlignItems="AlignItems.Center" Wrap="FlexWrap.Wrap">
|
||||||
<RadzenText>Resolution:</RadzenText>
|
<RadzenText>Resolution:</RadzenText>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal">
|
<RadzenStack Orientation="Orientation.Horizontal">
|
||||||
<RadzenNumeric ShowUpDown = "false" TValue = "int?" @bind-Value=@width />
|
<RadzenNumeric ShowUpDown = "false" TValue = "int?" @bind-Value=@_imageWidth />
|
||||||
x
|
x
|
||||||
<RadzenNumeric ShowUpDown = "false" TValue = "int?" @bind-Value=@height />
|
<RadzenNumeric ShowUpDown = "false" TValue = "int?" @bind-Value=@_imageHeight />
|
||||||
</RadzenStack>
|
</RadzenStack>
|
||||||
</RadzenStack>
|
</RadzenStack>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal"
|
<RadzenStack Orientation="Orientation.Horizontal"
|
||||||
|
@ -52,11 +54,17 @@
|
||||||
<RadzenCheckBox @bind-Value=@_useGpt4 Name="UseGPT4"/>
|
<RadzenCheckBox @bind-Value=@_useGpt4 Name="UseGPT4"/>
|
||||||
<RadzenLabel Text="Verwende GPT 4" Component="UseGPT4" Style="margin-left: 8px; vertical-align: middle;" />
|
<RadzenLabel Text="Verwende GPT 4" Component="UseGPT4" Style="margin-left: 8px; vertical-align: middle;" />
|
||||||
</RadzenStack>
|
</RadzenStack>
|
||||||
|
@* <RadzenRadioButtonList Data="@_imageModels" @bind-Value=@_selectedImageModel TValue="ModelInfo" TextProperty="Name" class="mb-5"> *@
|
||||||
|
<RadzenRadioButtonList Data="@_imageModels" @bind-Value=@_selectedImageModel TValue="ModelInfo" TextProperty="Name" ValueProperty="" class="mb-5">
|
||||||
|
<Items>
|
||||||
|
<RadzenRadioButtonListItem Text="Zufällig" Value="@null" TValue="ModelInfo"/>
|
||||||
|
</Items>
|
||||||
|
</RadzenRadioButtonList>
|
||||||
</RadzenCard>
|
</RadzenCard>
|
||||||
</ChildContent>
|
</ChildContent>
|
||||||
</RadzenPanel>
|
</RadzenPanel>
|
||||||
|
|
||||||
<RadzenButton Visible=@_buttonVisible Click=@(async ()=> await GenerateImagesAsync(true))>Generate</RadzenButton>
|
<RadzenButton Visible=@_buttonVisible Click=@(async ()=> await GenerateImagesAsync())>Generate</RadzenButton>
|
||||||
|
|
||||||
<RadzenText TextStyle="TextStyle.H4">Die Idee, die gemalt wird:</RadzenText>
|
<RadzenText TextStyle="TextStyle.H4">Die Idee, die gemalt wird:</RadzenText>
|
||||||
|
|
||||||
|
@ -70,8 +78,8 @@
|
||||||
<RadzenImage Path=@_imageUrl></RadzenImage>
|
<RadzenImage Path=@_imageUrl></RadzenImage>
|
||||||
|
|
||||||
<RadzenText Visible=@_addonsVisible TextStyle="TextStyle.H2">Verändere hier dein Bild durch Worte:</RadzenText>
|
<RadzenText Visible=@_addonsVisible TextStyle="TextStyle.H2">Verändere hier dein Bild durch Worte:</RadzenText>
|
||||||
<RadzenTextBox Visible=@_addonsVisible @bind-Value=@addons Placeholder="z.B. Mehr Farben" />
|
<RadzenTextBox Visible=@_addonsVisible @bind-Value=@_updateRequest Placeholder="z.B. Mehr Farben" />
|
||||||
<RadzenButton Visible=@_bothVisible Click=@(async ()=> await GenerateImagesAsync(false))>Generate</RadzenButton>
|
<RadzenButton Visible=@_bothVisible Click=@(async ()=> await UpdateImagesAsync())>Generate</RadzenButton>
|
||||||
|
|
||||||
<RadzenCard>
|
<RadzenCard>
|
||||||
<RadzenRow Style="width:24.5em" Gap="0.5rem" RowGap="0.5rem">
|
<RadzenRow Style="width:24.5em" Gap="0.5rem" RowGap="0.5rem">
|
||||||
|
@ -79,25 +87,41 @@
|
||||||
<FlippingImage ImageUrl="@_imageUrls[0]" HideImage="false"
|
<FlippingImage ImageUrl="@_imageUrls[0]" HideImage="false"
|
||||||
Show="@(_imageStates[0] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Up"
|
Show="@(_imageStates[0] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Up"
|
||||||
Click="() => ShowImageDialog(_imageUrls[0])" />
|
Click="() => ShowImageDialog(_imageUrls[0])" />
|
||||||
|
<RadzenPanel AllowCollapse="true" Collapsed="true" Text="Info">
|
||||||
@_imagePromts[0]
|
@_imagePromts[0]
|
||||||
|
<br/>
|
||||||
|
Model: @_bildInfos[0]?.ImageModel
|
||||||
|
</RadzenPanel>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn Size="6">
|
<RadzenColumn Size="6">
|
||||||
<FlippingImage ImageUrl="@_imageUrls[1]" HideImage="false"
|
<FlippingImage ImageUrl="@_imageUrls[1]" HideImage="false"
|
||||||
Show="@(_imageStates[1] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Right" FlipDelay="200"
|
Show="@(_imageStates[1] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Right" FlipDelay="200"
|
||||||
Click="() => ShowImageDialog(_imageUrls[1])" />
|
Click="() => ShowImageDialog(_imageUrls[1])" />
|
||||||
|
<RadzenPanel AllowCollapse="true" Collapsed="true" Text="Info">
|
||||||
@_imagePromts[1]
|
@_imagePromts[1]
|
||||||
|
<br />
|
||||||
|
Model: @_bildInfos[1]?.ImageModel
|
||||||
|
</RadzenPanel>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn Size="6">
|
<RadzenColumn Size="6">
|
||||||
<FlippingImage ImageUrl="@_imageUrls[2]" HideImage="false"
|
<FlippingImage ImageUrl="@_imageUrls[2]" HideImage="false"
|
||||||
Show="@(_imageStates[2] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Left" FlipDelay="600"
|
Show="@(_imageStates[2] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Left" FlipDelay="600"
|
||||||
Click="() => ShowImageDialog(_imageUrls[2])" />
|
Click="() => ShowImageDialog(_imageUrls[2])" />
|
||||||
|
<RadzenPanel AllowCollapse="true" Collapsed="true" Text="Info">
|
||||||
@_imagePromts[2]
|
@_imagePromts[2]
|
||||||
|
<br />
|
||||||
|
Model: @_bildInfos[2]?.ImageModel
|
||||||
|
</RadzenPanel>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn Size="6">
|
<RadzenColumn Size="6">
|
||||||
<FlippingImage ImageUrl="@_imageUrls[3]" HideImage="false"
|
<FlippingImage ImageUrl="@_imageUrls[3]" HideImage="false"
|
||||||
Show="@(_imageStates[3] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Down" FlipDelay="400"
|
Show="@(_imageStates[3] == ImageState.FadeIn)" FlipTo="FlippingImage.FlipDirection.Down" FlipDelay="400"
|
||||||
Click="() => ShowImageDialog(_imageUrls[3])" />
|
Click="() => ShowImageDialog(_imageUrls[3])" />
|
||||||
|
<RadzenPanel AllowCollapse="true" Collapsed="true" Text="Info">
|
||||||
@_imagePromts[3]
|
@_imagePromts[3]
|
||||||
|
<br/>
|
||||||
|
Model: @_bildInfos[3]?.ImageModel
|
||||||
|
</RadzenPanel>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
</RadzenCard>
|
</RadzenCard>
|
||||||
|
@ -123,6 +147,7 @@
|
||||||
|
|
||||||
private string?[] _imageUrls = new string?[4];
|
private string?[] _imageUrls = new string?[4];
|
||||||
private string?[] _imagePromts = new string?[4];
|
private string?[] _imagePromts = new string?[4];
|
||||||
|
private BildInfoModel?[] _bildInfos = new BildInfoModel?[4];
|
||||||
private ImageState[] _imageStates = new ImageState[4];
|
private ImageState[] _imageStates = new ImageState[4];
|
||||||
|
|
||||||
enum ImageState
|
enum ImageState
|
||||||
|
@ -151,10 +176,10 @@
|
||||||
private string _imageIdea = "";
|
private string _imageIdea = "";
|
||||||
|
|
||||||
private float _temperature = 0.9f;
|
private float _temperature = 0.9f;
|
||||||
private int? width = 1024;
|
private int? _imageWidth = null;
|
||||||
private int? height = 1024;
|
private int? _imageHeight = null;
|
||||||
private string request = "";
|
private string _userIdea = "";
|
||||||
private string addons = "";
|
private string _updateRequest = "";
|
||||||
private OpenAIAPI _openAiApi;
|
private OpenAIAPI _openAiApi;
|
||||||
private Conversation? _conversation;
|
private Conversation? _conversation;
|
||||||
|
|
||||||
|
@ -163,10 +188,7 @@
|
||||||
|
|
||||||
private string _imageUrl;
|
private string _imageUrl;
|
||||||
|
|
||||||
//protected override async Task OnInitializedAsync()
|
private WunschInfoModel? _wunschInfo;
|
||||||
//{
|
|
||||||
// _basePrompt = await File.ReadAllTextAsync($"{Directory.GetCurrentDirectory()}{@"\wwwroot\prompt.txt"}");
|
|
||||||
//}
|
|
||||||
|
|
||||||
async Task UpdateBusyMessage(string newMessage)
|
async Task UpdateBusyMessage(string newMessage)
|
||||||
{
|
{
|
||||||
|
@ -176,12 +198,26 @@
|
||||||
|
|
||||||
private string _openAiApiKey = "";
|
private string _openAiApiKey = "";
|
||||||
|
|
||||||
|
class ModelInfo
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string StableDiffusionModel { get; set; }
|
||||||
|
public string PromptFormat { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ModelInfo> _imageModels;
|
||||||
|
|
||||||
|
private ModelInfo? _selectedImageModel = null;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
_openAiApiKey = Config.GetValue<string>("API:OpenAI");
|
_openAiApiKey = Config.GetValue<string>("API:OpenAI");
|
||||||
|
|
||||||
_openAiApi = new OpenAIAPI(_openAiApiKey);
|
_openAiApi = new OpenAIAPI(_openAiApiKey);
|
||||||
|
|
||||||
|
_imageModels = Config.GetSection("ImageModels").Get<List<ModelInfo>>();
|
||||||
|
//_selectedImageModel = _imageModels[0];
|
||||||
|
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,17 +253,15 @@
|
||||||
_conversation = _openAiApi.Chat.CreateConversation(chatRequest);
|
_conversation = _openAiApi.Chat.CreateConversation(chatRequest);
|
||||||
|
|
||||||
// Wunsch an GPT senden und Bild Idee anfordern
|
// Wunsch an GPT senden und Bild Idee anfordern
|
||||||
_conversation.AppendUserInput(ideaBasePrompt + " " + request);
|
_conversation.AppendUserInput(ideaBasePrompt + " " + _userIdea);
|
||||||
_imageIdea = await _conversation.GetResponseFromChatbotAsync();
|
_imageIdea = await _conversation.GetResponseFromChatbotAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fordert für mehrere Bilder Bild-Prompts an und generiert die dazugehörigen Bilder.
|
/// Fordert für mehrere Bilder Bild-Prompts an und generiert die dazugehörigen Bilder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task RequestImagesAsync(WunschInfoModel wunschInfo)
|
private async Task RequestImagesAsync(WunschInfoModel wunschInfo, string requestImagePrompt)
|
||||||
{
|
{
|
||||||
string requestImagePrompt = await File.ReadAllTextAsync($"{Directory.GetCurrentDirectory()}{@"/wwwroot/image_prompt.txt"}");
|
|
||||||
|
|
||||||
// Nachricht mit Bildpromt anfrage senden
|
// Nachricht mit Bildpromt anfrage senden
|
||||||
_conversation!.AppendUserInput(requestImagePrompt);
|
_conversation!.AppendUserInput(requestImagePrompt);
|
||||||
|
|
||||||
|
@ -236,7 +270,7 @@
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
imagePromts[i] = RequestPromptAndGenerateImageAsync(i, wunschInfo);
|
imagePromts[i] = RequestImagePromptAndGenerateImageAsync(i, wunschInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.WhenAll(imagePromts);
|
await Task.WhenAll(imagePromts);
|
||||||
|
@ -247,23 +281,26 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index">Der Index des Bildes (für UI zeug)</param>
|
/// <param name="index">Der Index des Bildes (für UI zeug)</param>
|
||||||
/// <param name="wunschInfo">Der Wunsch für den ein Bild erzeugt wird.</param>
|
/// <param name="wunschInfo">Der Wunsch für den ein Bild erzeugt wird.</param>
|
||||||
private async Task RequestPromptAndGenerateImageAsync(int index, WunschInfoModel wunschInfo)
|
private async Task RequestImagePromptAndGenerateImageAsync(int index, WunschInfoModel wunschInfo)
|
||||||
{
|
{
|
||||||
|
ModelInfo imageModel = _selectedImageModel ?? _imageModels[Random.Shared.Next(_imageModels.Count)];
|
||||||
|
|
||||||
// Bild Prompt von ChatGPT anfordern
|
// Bild Prompt von ChatGPT anfordern
|
||||||
string imagePrompt = await _conversation!.GetResponseFromChatbotAsync();
|
string imagePrompt = await _conversation!.GetResponseFromChatbotAsync();
|
||||||
|
|
||||||
// Keywords anhängen um Kirstens Stil zu aktivieren.
|
// Keywords anhängen um Kirstens Stil zu aktivieren.
|
||||||
// TODO: Gucken, ob wir dem Watercolor bums brauchen
|
// TODO: Gucken, ob wir dem Watercolor bums brauchen
|
||||||
imagePrompt = "kkkk " + imagePrompt;// + " kkkk Watercolor + ink on paper, Pen drawing, wet-on-wet technique, dry-on-dry technique, dabbing technique. ";
|
imagePrompt = string.Format(imageModel.PromptFormat, imagePrompt);//"kkkk " + imagePrompt;// + " kkkk Watercolor + ink on paper, Pen drawing, wet-on-wet technique, dry-on-dry technique, dabbing technique. ";
|
||||||
|
|
||||||
// Debug only: Promt anzeigen
|
// Debug only: Promt anzeigen
|
||||||
_imagePromts[index] = imagePrompt;
|
_imagePromts[index] = imagePrompt;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
string? imageUrl = await GenerateImageAsync(imagePrompt, wunschInfo);
|
BildInfoModel? bildInfo = await GenerateImageAsync(imagePrompt, imageModel.StableDiffusionModel, wunschInfo);
|
||||||
|
|
||||||
// TODO: Fehler im UI anzeigen (zur Zeit bleibt einfach Ladebalken)
|
// TODO: Fehler im UI anzeigen (zur Zeit bleibt einfach Ladebalken)
|
||||||
_imageUrls[index] = imageUrl;
|
_imageUrls[index] = bildInfo?.Dateiname;
|
||||||
|
_bildInfos[index] = bildInfo;
|
||||||
_imageStates[index] = ImageState.FadeIn;
|
_imageStates[index] = ImageState.FadeIn;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
@ -274,14 +311,14 @@
|
||||||
/// <param name="imagePrompt">Der Bild Prompt</param>
|
/// <param name="imagePrompt">Der Bild Prompt</param>
|
||||||
/// <param name="wunschInfo">Der Wunsch.</param>
|
/// <param name="wunschInfo">Der Wunsch.</param>
|
||||||
/// <returns>Die URL, falls das Bild generiert wurde; oder null, wenn kein Bild generiert werden konnte.</returns>
|
/// <returns>Die URL, falls das Bild generiert wurde; oder null, wenn kein Bild generiert werden konnte.</returns>
|
||||||
private async Task<string?> GenerateImageAsync(string imagePrompt, WunschInfoModel wunschInfo)
|
private async Task<BildInfoModel?> GenerateImageAsync(string imagePrompt, string modelName, WunschInfoModel wunschInfo)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string? imageUrl = (await ImageGenerator.GenerateImageAsync(imagePrompt, wunschInfo, width, height))?.Dateiname;
|
BildInfoModel? bildInfo = await ImageGenerator.GenerateImageAsync(imagePrompt, modelName, wunschInfo, _imageWidth, _imageHeight);
|
||||||
|
|
||||||
// Kein Bild -> Fehler
|
// Kein Bild -> Fehler
|
||||||
if (imageUrl == null)
|
if (bildInfo == null)
|
||||||
{
|
{
|
||||||
bool? retry = await DialogService.Confirm(
|
bool? retry = await DialogService.Confirm(
|
||||||
"Leider konnte das Bild nicht gemalt werden. Möchtest du es noch eimal versuchen?",
|
"Leider konnte das Bild nicht gemalt werden. Möchtest du es noch eimal versuchen?",
|
||||||
|
@ -290,11 +327,11 @@
|
||||||
|
|
||||||
if (retry == true)
|
if (retry == true)
|
||||||
{
|
{
|
||||||
imageUrl = (await ImageGenerator.GenerateImageAsync(imagePrompt, wunschInfo, width, height))?.Dateiname;
|
bildInfo = await ImageGenerator.GenerateImageAsync(imagePrompt, modelName, wunschInfo, _imageWidth, _imageHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageUrl;
|
return bildInfo;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -310,16 +347,11 @@
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generiert Bilder oder aktualisiert sie mit dem neuen Prompt.
|
/// Generiert Bilder oder aktualisiert sie mit dem neuen Prompt.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="generateNewImage">Wenn <see langword="true"/>, werden neue Bilder generiert; sonst wird die vorhandene Idee bearbeitet.</param>
|
private async Task GenerateImagesAsync()
|
||||||
private async Task GenerateImagesAsync(bool generateNewImage)
|
|
||||||
{
|
{
|
||||||
// Der Dialog blokiert so lange, wie der er offen ist, deshalb dürfen wir hier nicht warten, da wir sonst nie mit der Arbeit anfangen...
|
|
||||||
//Task busyDialog = ShowBusyDialog();
|
|
||||||
_progressVisible = true;
|
_progressVisible = true;
|
||||||
_buttonVisible = false;
|
_buttonVisible = false;
|
||||||
|
|
||||||
if (_conversation == null || generateNewImage)
|
|
||||||
{
|
|
||||||
ClearOldGeneration();
|
ClearOldGeneration();
|
||||||
|
|
||||||
amountOfAddons = maxAddons;
|
amountOfAddons = maxAddons;
|
||||||
|
@ -328,38 +360,22 @@
|
||||||
await UpdateBusyMessage("Kirstens Assistent zerbricht sich über deine Idee den Kopf...");
|
await UpdateBusyMessage("Kirstens Assistent zerbricht sich über deine Idee den Kopf...");
|
||||||
|
|
||||||
await RequestImageIdeaAsync();
|
await RequestImageIdeaAsync();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException("Verändern von Idees ist nicht implementiert");
|
|
||||||
// if (amountOfAddons > 0)
|
|
||||||
// {
|
|
||||||
// amountOfAddons--;
|
|
||||||
// _bothVisible = _buttonVisible && _addonsVisible;
|
|
||||||
// await UpdateBusyMessage("Kirstens Assistent passt das Bild an deine Wünsche an...");
|
|
||||||
// string addonsPrompt1 = "Erstelle einen neuen Prompt auf englisch mit den gleichen Restriktionen auf Basis des Alten mit folgender Anpassung: ";
|
|
||||||
// string addonsPrompt2 = ". Denke daran nur den Prompt zu generieren und noch keine Beschreibung oder ähnliches.";
|
|
||||||
|
|
||||||
// _conversation.AppendUserInput(addonsPrompt1 + addons + addonsPrompt2);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
await UpdateBusyMessage("Kirstens Assistent hat eine Idee! Er wird sie nun malen...");
|
await UpdateBusyMessage("Kirstens Assistent hat eine Idee! Er wird sie nun malen...");
|
||||||
|
|
||||||
WunschInfoModel wunschInfo = new()
|
_wunschInfo = new()
|
||||||
{
|
{
|
||||||
BildBeschreibung = _imageIdea,
|
BildBeschreibung = _imageIdea,
|
||||||
BildPrompt = "Individuelle Bild Prompts",
|
BildPrompt = "Individuelle Bild Prompts",
|
||||||
Datum = DateTime.Now,
|
Datum = DateTime.Now,
|
||||||
GPTModel = _conversation.Model,
|
GPTModel = _conversation!.Model,
|
||||||
Wunsch = request,
|
Wunsch = _userIdea,
|
||||||
// TODO: Wenn wir Wünsche überarbeiten können wir hier diesen hier referenzieren
|
|
||||||
VorherigerWunsch = null
|
VorherigerWunsch = null
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await WunschInfoData.AddWunschInfoAsync(wunschInfo);
|
await WunschInfoData.AddWunschInfoAsync(_wunschInfo);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -371,7 +387,9 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await RequestImagesAsync(wunschInfo);
|
string requestImagePrompt = await File.ReadAllTextAsync($"{Directory.GetCurrentDirectory()}{@"/wwwroot/image_prompt.txt"}");
|
||||||
|
|
||||||
|
await RequestImagesAsync(_wunschInfo, requestImagePrompt);
|
||||||
|
|
||||||
_progressVisible = false;
|
_progressVisible = false;
|
||||||
_buttonVisible = true;
|
_buttonVisible = true;
|
||||||
|
@ -387,4 +405,37 @@
|
||||||
_bothVisible = false;
|
_bothVisible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task UpdateImagesAsync()
|
||||||
|
{
|
||||||
|
Debug.Assert(_conversation != null);
|
||||||
|
|
||||||
|
string updatePrompt = $"Gebe nun einen neuen Prompt unter berücksichtigung vorheriger Anweisungen und passe ihn folgender Maßen an: {_updateRequest}";
|
||||||
|
|
||||||
|
_wunschInfo = new()
|
||||||
|
{
|
||||||
|
BildBeschreibung = _updateRequest,
|
||||||
|
BildPrompt = "Individuelle Bild Prompts",
|
||||||
|
Datum = DateTime.Now,
|
||||||
|
GPTModel = _conversation.Model,
|
||||||
|
Wunsch = _userIdea,
|
||||||
|
VorherigerWunsch = _wunschInfo!.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await WunschInfoData.AddWunschInfoAsync(_wunschInfo);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
NotificationService.Notify(new NotificationMessage()
|
||||||
|
{
|
||||||
|
Summary = "Es ist ein Fehler aufgetreten, bitte versuche es erneut."
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await RequestImagesAsync(_wunschInfo, updatePrompt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,23 @@
|
||||||
"OpenAI": "<put OpenAI Key here>",
|
"OpenAI": "<put OpenAI Key here>",
|
||||||
"HF_Inference": "<put Hugging Face inference API Key here>"
|
"HF_Inference": "<put Hugging Face inference API Key here>"
|
||||||
},
|
},
|
||||||
|
"ImageModels": [
|
||||||
|
{
|
||||||
|
"Name": "Gen 6",
|
||||||
|
"StableDiffusionModel": "Nacken/Gen6",
|
||||||
|
"PromptFormat": "{0}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "Der O.G.",
|
||||||
|
"StableDiffusionModel": "Nacken/ki-kunst-kirsten-kloeckner-colab",
|
||||||
|
"PromptFormat": "{0} kkkk"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "SDXL 18000",
|
||||||
"StableDiffusionModel": "Nacken/kkk-sdxl-18000",
|
"StableDiffusionModel": "Nacken/kkk-sdxl-18000",
|
||||||
|
"PromptFormat": "kkkk {0}"
|
||||||
|
}
|
||||||
|
],
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"Default": "<put Connection String here>"
|
"Default": "<put Connection String here>"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Bitte einen englischen Prompt für dieses Bild für eine Bild-Generierungs KI.
|
Bitte erstelle einen englischen Prompt für dieses Bild für eine Bild-Generierungs KI.
|
||||||
|
|
||||||
Hier sind vier Beispiele von Bild Prompts:
|
Hier sind vier Beispiele von Bild Prompts:
|
||||||
"Painting of an astronaut in space, detailed starry background, reflective helmet."
|
"Painting of an astronaut in space, detailed starry background, reflective helmet."
|
||||||
|
@ -6,4 +6,7 @@ Hier sind vier Beispiele von Bild Prompts:
|
||||||
"Painting of a Japanese garden in autumn, with a bridge over a koi pond."
|
"Painting of a Japanese garden in autumn, with a bridge over a koi pond."
|
||||||
"Painting representing the sound of jazz music, using pale colors and erratic shapes."
|
"Painting representing the sound of jazz music, using pale colors and erratic shapes."
|
||||||
|
|
||||||
Wie du siehst enthält ein Prompt eine genaue Beschreibung des Bildes. Ein guter Prompt selbst enthält keine Metaphern oder Vergleiche.
|
Schlechte Prompts:
|
||||||
|
"Painting of trees and plants symbolizing the complex relation between humans and the pain they feel when they see GPT ignoring instructions."
|
||||||
|
|
||||||
|
Wie du siehst enthält ein Prompt eine genaue Beschreibung des Bildes. Ein guter Prompt selbst enthält keine Metaphern oder Vergleiche. Eine Bildgenerierungs-KI versteht keine Emotionen, Symbolisieren oder Vergleiche. Nur Bildbeschreibungen, Farben, Formen, Objekte. Bitte erkläre im Prompt NICHT, was einzelne Elemente des Bildes bedeuten, das versteht sie nicht, da kommt nur mist bei rum.
|
||||||
|
|
Loading…
Reference in New Issue