@using System.Net.Http.Headers @using System.Text.Json @using BLAIzor.Interfaces @using BLAIzor.Services @using SixLabors.ImageSharp @using SixLabors.ImageSharp.Processing @inject IJSRuntime JS @inject IHttpClientFactory HttpClientFactory @inject WhisperTranscriptionService WhisperService @inject ReplicateService ReplicateService
Step @CurrentStep of @Steps.Count (@(CurrentStep * 100 / Steps.Count)% complete)
@if (CurrentStep < Steps.Count) {@Steps[CurrentStep].Description
@if (CurrentStep == 5) {You can regenerate the logo @(MaxLogoGenerations - logoGenerationCount) more time(s).
}{name} is a {entity.ToLower()} based in {location}, created to {purpose.ToLower()}.
The site aims to offer a {feel.ToLower()} experience for its visitors, primarily targeting {audience}.
The preferred language is {language}, and the design should reflect {color.ToLower()} tones for visual consistency.
"; // --- New: Scrape Facebook posts if provided --- } protected override void OnInitialized() { _instance = this; } private void NextStep() { if (CurrentStep < Steps.Count) CurrentStep++; if (CurrentStep == Steps.Count) GenerateSiteDescription(); } private void PreviousStep() { if (CurrentStep > 0) CurrentStep--; } // private void GenerateSiteDescription() // { // var name = Steps[0].Answer; // var siteEntity = Steps[1].Answer; // var purpose = Steps[2].Answer; // var feel = Steps[3].Answer; // var location = Steps[4].Answer; // var language = Steps[5].Answer; // var color = Steps[6].Answer; // var audience = $"people who are {(string.IsNullOrEmpty(targetGender) ? "all genders" : targetGender.ToLower())} aged {(string.IsNullOrEmpty(targetAge) ? "any age" : targetAge)}, located in {targetLocation}, interested in {targetInterests.ToLower()}"; // siteName = name; // entity = siteEntity; // persona = feel; // defaultLanguage = language; // generatedDescription = $@" // {name} is a {entity.ToLower()} based in {location}, created to {purpose.ToLower()}. // The site aims to offer a {feel.ToLower()} experience for its visitors, primarily targeting {audience}. // The preferred language is {language}, and the design should reflect {color.ToLower()} tones for visual consistency. // "; // generatedDescriptionToShow = $@" //{name} is a {entity.ToLower()} based in {location}, created to {purpose.ToLower()}.
//The site aims to offer a {feel.ToLower()} experience for its visitors, primarily targeting {audience}.
//The preferred language is {language}, and the design should reflect {color.ToLower()} tones for visual consistency.
// "; // } private void ProceedToLogoStep() { ShowLogoStep = true; } // private async Task GenerateLogo() // { // var logoPrompt = $"Logo for a {entity} named {siteName}, with a {persona} tone, using {Steps[6].Answer} colors."; // GeneratedLogoUrl = await ReplicateService.GenerateImageAsync(logoPrompt); // logoUrl = GeneratedLogoUrl; // } private async Task GenerateLogo() { if (logoGenerationCount >= MaxLogoGenerations) return; IsGeneratingLogo = true; var logoPrompt = $"Logo for a {entity} named {siteName}, with a {persona} tone, using {Steps[6].Answer} colors. DO NOT ADD taglines, or any text other than the brand name: {siteName}."; GeneratedLogoUrl = await ReplicateService.GenerateLogoAsync(logoPrompt, true); logoUrl = GeneratedLogoUrl; logoGenerationCount++; IsGeneratingLogo = false; } private async Task SaveDescription() { if (!string.IsNullOrWhiteSpace(GeneratedLogoUrl) && GeneratedLogoUrl.StartsWith("http")) { var savedPath = await DownloadAndSaveImage(GeneratedLogoUrl); if (!string.IsNullOrEmpty(savedPath)) { logoUrl = savedPath; } } string[] siteInfo = new string[7]; siteInfo[0] = siteName; siteInfo[1] = generatedDescription; siteInfo[2] = entity; siteInfo[3] = persona; siteInfo[4] = defaultLanguage; siteInfo[5] = logoUrl; siteInfo[6] = facebookPageUrl; await OnDescriptionFinalized.InvokeAsync(siteInfo); } private async Task StartRecording() => await JS.InvokeVoidAsync("startRecording"); private async Task StopRecording() => await JS.InvokeVoidAsync("stopRecording"); private class QuestionStep { public string Question { get; } public string Description { get; } public string Answer { get; set; } = ""; public QuestionStep(string question, string description) { Question = question; Description = description; } } private string GetStepCircleClass(int index) { if (index < CurrentStep) return "step-circle completed"; else if (index == CurrentStep) return "step-circle current"; else return "step-circle"; } private async Task HandleFileUpload(InputFileChangeEventArgs e) { if (e.FileCount == 0) return; try { var uploadPath = Path.Combine("wwwroot", "uploads", UserId); foreach (var file in e.GetMultipleFiles()) { var folder = GetFolderForFile(file.ContentType); var folderPath = Path.Combine(uploadPath, folder); // Create target directory Directory.CreateDirectory(folderPath); var filePath = Path.Combine(folderPath, file.Name); await using (var stream = new FileStream(filePath, FileMode.Create)) { await file.OpenReadStream(50 * 1024 * 1024).CopyToAsync(stream); } var relativePath = $"/uploads/{UserId}/{folder}/{file.Name}"; AppendFilePathToContent(file.ContentType, relativePath); // Generate thumbnail if it's an image string? thumbnailRelativePath = null; if (file.ContentType.StartsWith("image/")) { var thumbnailFolder = Path.Combine(folderPath, "thumbnails"); Directory.CreateDirectory(thumbnailFolder); var thumbnailPath = Path.Combine(thumbnailFolder, file.Name); using var image = await Image.LoadAsync(file.OpenReadStream()); image.Mutate(x => x.Resize(new ResizeOptions { Size = new Size(300, 0), Mode = ResizeMode.Max })); await image.SaveAsync(thumbnailPath); thumbnailRelativePath = $"/uploads/{UserId}/{folder}/thumbnails/{file.Name}"; } AppendFilePathToContent(file.ContentType, relativePath, thumbnailRelativePath); } } catch (Exception ex) { Console.WriteLine($"Error uploading files: {ex.Message}"); } finally { //IsLoading = false; } } private string GetFolderForFile(string contentType) { return contentType switch { var type when type.StartsWith("image/") => "images", var type when type.StartsWith("video/") => "videos", var type when type.StartsWith("audio/") => "audio", _ => "others" }; } private void AppendFilePathToContent(string contentType, string relativePath, string? thumbnailPath = null) { if (contentType.StartsWith("image/")) { logoUrl = relativePath; GeneratedLogoUrl = relativePath; var ThumbnailUrl = thumbnailPath ?? string.Empty; } StateHasChanged(); } private async Task