diff --git a/AiPrompt/AiPrompt.csproj b/AiPrompt/AiPrompt.csproj index 64598ca..67410eb 100644 --- a/AiPrompt/AiPrompt.csproj +++ b/AiPrompt/AiPrompt.csproj @@ -16,7 +16,7 @@ AiPrompt - com.companyname.aiprompt + com.xueque.aiprompt 5FBB22BC-690D-4055-91AE-385FF906F628 @@ -30,34 +30,41 @@ 10.0.17763.0 6.5 10 + False + True + EA74CA5ABC054780009410D9CBCB64B048E72F85 + SHA256 + False + False + True + 0 - + - + + - + - - - - - + + + diff --git a/AiPrompt/Data/BaseModel.cs b/AiPrompt/Data/BaseModel.cs new file mode 100644 index 0000000..f8d4566 --- /dev/null +++ b/AiPrompt/Data/BaseModel.cs @@ -0,0 +1,14 @@ +using SQLite; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AiPrompt.Data; + +public class BaseModel +{ + [PrimaryKey] + public string Id { get; set; } +} diff --git a/AiPrompt/Data/Config.cs b/AiPrompt/Data/Config.cs new file mode 100644 index 0000000..5867eb8 --- /dev/null +++ b/AiPrompt/Data/Config.cs @@ -0,0 +1,12 @@ +using SQLite; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AiPrompt.Data; + +public class Config:BaseModel{ + public string SourcePath { get; set; } +} diff --git a/AiPrompt/Data/Prompt.cs b/AiPrompt/Data/Prompt.cs index 85eff56..144739e 100644 --- a/AiPrompt/Data/Prompt.cs +++ b/AiPrompt/Data/Prompt.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,8 +12,23 @@ namespace AiPrompt.Data; public class Prompt{ public string Key { get; set; } public string Name { get; set; } - public string Image { get; set; } + + private string image; + public string Image { get=> image; set{ + image = LocalFile2Base64(value); + }} + + private string LocalFile2Base64(string value) + { + if (!File.Exists(value)){ + return value; + } + string base64 = $"data:image/png;base64,{Convert.ToBase64String(File.ReadAllBytes(value))}"; + return base64; + } + public bool Active { get; set; } + } diff --git a/AiPrompt/MauiProgram.cs b/AiPrompt/MauiProgram.cs index 584c388..0be68b7 100644 --- a/AiPrompt/MauiProgram.cs +++ b/AiPrompt/MauiProgram.cs @@ -1,6 +1,6 @@ using AiPrompt.Service; using AiPrompt.Service.Impl; -using Microsoft.AspNetCore.Components.WebView.Maui; +using AiPrompt.Util; namespace AiPrompt; @@ -27,9 +27,10 @@ public static MauiApp CreateMauiApp() options.Primary = "#7160E8"; }); }); - - builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); return builder.Build(); diff --git a/AiPrompt/Pages/CopyComponent.razor b/AiPrompt/Pages/CopyComponent.razor index 09180b0..baad093 100644 --- a/AiPrompt/Pages/CopyComponent.razor +++ b/AiPrompt/Pages/CopyComponent.razor @@ -1,6 +1,6 @@  - mdi-note-multiple-outline @@ -12,16 +12,23 @@ 已复制到剪切板 - - Close + 关闭 @code { + private string text; [Parameter] - public string Text { get; set; } + public string Text { get{ + if (!text.EndsWith(",")) + { + return $"{text},"; + } + return text; + } set=>text=value; } private bool open = false; } diff --git a/AiPrompt/Pages/ListItemComponent.razor b/AiPrompt/Pages/ListItemComponent.razor index a9f9627..ef303ff 100644 --- a/AiPrompt/Pages/ListItemComponent.razor +++ b/AiPrompt/Pages/ListItemComponent.razor @@ -1,4 +1,5 @@ @using AiPrompt.Data +@using System.Net @Prompt.Name @@ -17,5 +18,6 @@ public EventCallback PromptChanged { get; set; } + private string defaultImage = "data:image/png;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7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jBAIIPX6fzrdRdQ0QfYph9tJOYZS4UsvAy/oRkA4Bz165rFvWk+2TGWNEfILKhJAyAeCev5CtKb1cTOok1dFNvvGinErnvRW9jnP/2Q=="; -} +} \ No newline at end of file diff --git a/AiPrompt/Pages/PromptList.razor b/AiPrompt/Pages/PromptList.razor index b55f770..373c7c6 100644 --- a/AiPrompt/Pages/PromptList.razor +++ b/AiPrompt/Pages/PromptList.razor @@ -1,15 +1,14 @@ @page "/{Key}" @using AiPrompt.Data @using AiPrompt.Service +@using AiPrompt.Util @inject StateContainer stateContainer @inject IPromptService promptService @implements IDisposable - - - - - + + + diff --git a/AiPrompt/Platforms/Windows/Package.appxmanifest b/AiPrompt/Platforms/Windows/Package.appxmanifest index 2bcb11e..7e50e9f 100644 --- a/AiPrompt/Platforms/Windows/Package.appxmanifest +++ b/AiPrompt/Platforms/Windows/Package.appxmanifest @@ -5,7 +5,7 @@ xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap rescap"> - + $placeholder$ diff --git a/AiPrompt/Resources/AppIcon/aiprompt.svg b/AiPrompt/Resources/AppIcon/aiprompt.svg new file mode 100644 index 0000000..8f84506 --- /dev/null +++ b/AiPrompt/Resources/AppIcon/aiprompt.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/AiPrompt/Service/IConfigService.cs b/AiPrompt/Service/IConfigService.cs new file mode 100644 index 0000000..d1abdd8 --- /dev/null +++ b/AiPrompt/Service/IConfigService.cs @@ -0,0 +1,10 @@ +using AiPrompt.Data; + +namespace AiPrompt.Service; + +public interface IConfigService +{ + public Task SaveConfig(Config config); + public Task GetConfig(); + +} diff --git a/AiPrompt/Service/ISourceService.cs b/AiPrompt/Service/ISourceService.cs index 0d93e6c..933ea34 100644 --- a/AiPrompt/Service/ISourceService.cs +++ b/AiPrompt/Service/ISourceService.cs @@ -19,7 +19,9 @@ public interface ISourceService{ public Task> ReadCategoriesAsync(); - public Task> AllSourceAsync(); + public Task> AllSourceAsync(); + + public Task GetSourcePathAsync(); public IEnumerable ReadPrefabPrompts(string key); public Task> ReadPrefabPromptsAsync(string key); diff --git a/AiPrompt/Service/Impl/ConfigService.cs b/AiPrompt/Service/Impl/ConfigService.cs new file mode 100644 index 0000000..d3e17bc --- /dev/null +++ b/AiPrompt/Service/Impl/ConfigService.cs @@ -0,0 +1,44 @@ +using AiPrompt.Data; +using AiPrompt.Util; + +namespace AiPrompt.Service.Impl; + +public class ConfigService : IConfigService{ + public ConfigService(Db db) + { + this.db = db; + } + private readonly Db db; + + private string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"); + + + public async Task SaveConfig(Config config) + { + config.Id = nameof(config); + await db.SaveAsync(config); + //using(var fs = new FileStream(path, FileMode.Create, FileAccess.Write)) + //{ + // try + // { + // await JsonSerializer.SerializeAsync(fs, config,new JsonSerializerOptions(){ WriteIndented = true }); + // } + // catch { } + //} + } + + public async Task GetConfig() + { + return await db.GetAsync(); + //using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) + //{ + // try + // { + // var config = await JsonSerializer.DeserializeAsync(fs); + // return config; + // } + // catch { return null; } + + //} + } +} diff --git a/AiPrompt/Service/Impl/PromptService.cs b/AiPrompt/Service/Impl/PromptService.cs index 2ac2291..a46e53f 100644 --- a/AiPrompt/Service/Impl/PromptService.cs +++ b/AiPrompt/Service/Impl/PromptService.cs @@ -1,6 +1,5 @@ using AiPrompt.Data; -using OfficeOpenXml; -using System.Linq; +using AiPrompt.Util; namespace AiPrompt.Service.Impl; diff --git a/AiPrompt/Service/Impl/SourceService.cs b/AiPrompt/Service/Impl/SourceService.cs index a2684bb..58a1579 100644 --- a/AiPrompt/Service/Impl/SourceService.cs +++ b/AiPrompt/Service/Impl/SourceService.cs @@ -1,15 +1,17 @@ using AiPrompt.Data; +using AiPrompt.Util; using OfficeOpenXml; -using OneOf.Types; namespace AiPrompt.Service.Impl; internal class SourceService : ISourceService{ - public SourceService(StateContainer stateContainer){ + public SourceService(StateContainer stateContainer,IConfigService configService){ this.stateContainer = stateContainer; + this.configService = configService; } private readonly StateContainer stateContainer; + private readonly IConfigService configService; /// /// 获取目录下所有文件 @@ -18,16 +20,25 @@ public SourceService(StateContainer stateContainer){ /// /// private async Task FillDirectoryAllSource(string dir, List list){ + if (dir is null) return; await Task.Run(async () =>{ DirectoryInfo d = new (dir); - FileInfo[] files = d.GetFiles();//文件 - DirectoryInfo[] directs = d.GetDirectories();//文件夹 - foreach (FileInfo f in files){ - list.Add(new(f.Name, f.FullName));//添加文件名到列表中 - } - //获取子文件夹内的文件列表,递归遍历 - foreach (DirectoryInfo dd in directs){ - await FillDirectoryAllSource(dd.FullName, list); + if (d.Exists) + { + FileInfo[] files = d.GetFiles();//文件 + DirectoryInfo[] directs = d.GetDirectories();//文件夹 + foreach (FileInfo f in files) + { + if (f.Extension is ".xlsx" or ".xls") + { + list.Add(new(f.Name, f.FullName));//添加文件名到列表中 + } + } + //获取子文件夹内的文件列表,递归遍历 + foreach (DirectoryInfo dd in directs) + { + await FillDirectoryAllSource(dd.FullName, list); + } } }); } @@ -35,12 +46,17 @@ await Task.Run(async () =>{ /// 获取所有咒语书 /// /// - public async Task> AllSourceAsync(){ + public async Task> AllSourceAsync(){ List sources = new (); - var path = Path.Combine(AppContext.BaseDirectory,"Sources"); + var path = await GetSourcePathAsync(); await FillDirectoryAllSource(path, sources); return sources; } + + public async Task GetSourcePathAsync(){ + Config config = await configService.GetConfig(); + return config?.SourcePath; + } /// /// 读取咒语 /// @@ -49,25 +65,35 @@ public async Task> AllSourceAsync(){ public IEnumerable ReadPrompts(string categoryKey){ ExcelPackage.LicenseContext = LicenseContext.NonCommercial; List list = new (); - using (ExcelPackage excelPackage = new (stateContainer.Source?.Path)){ - try{ - ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets[0]; - for (int i = 1; i <= excelWorksheet.Dimension?.End.Column; i++){ - if (i % 3 == 1){ - string category = excelWorksheet.Cells[1, i].GetCellValue(); - if (category.Equals(categoryKey)){ - for (int j = 2; j <= excelWorksheet.Dimension?.End.Row; j++){ - string key = excelWorksheet.Cells[j, i].GetCellValue(); - if (string.IsNullOrEmpty(key)) break; - string name = excelWorksheet.Cells[j, i + 1].GetCellValue(); - string image = excelWorksheet.Cells[j, i + 2].GetCellValue(); - list.Add(new () { Name = name, Key = key, Image = image }); + if (stateContainer.Source is not null) + { + using (ExcelPackage excelPackage = new(stateContainer.Source.Path)) + { + try + { + ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets[0]; + for (int i = 1; i <= excelWorksheet.Dimension?.End.Column; i++) + { + if (i % 3 == 1) + { + string category = excelWorksheet.Cells[1, i].GetCellValue(); + if (category.Equals(categoryKey)) + { + for (int j = 2; j <= excelWorksheet.Dimension?.End.Row; j++) + { + string key = excelWorksheet.Cells[j, i].GetCellValue(); + if (string.IsNullOrEmpty(key)) break; + string name = excelWorksheet.Cells[j, i + 1].GetCellValue(); + string image = excelWorksheet.Cells[j, i + 2].GetCellValue(); + list.Add(new() { Name = name, Key = key, Image = image }); + } + break; } - break; } } } - }catch{ } + catch { } + } } return list; } @@ -88,16 +114,24 @@ public async Task> ReadCategoriesAsync(){ public IEnumerable ReadCategories(){ ExcelPackage.LicenseContext = LicenseContext.NonCommercial; List list = new (); - using (ExcelPackage excelPackage = new (stateContainer.Source?.Path)){ - try{ - ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets[0]; - for (int i = 1; i <= excelWorksheet.Dimension?.End.Column; i++){ - if (i % 3 == 1){ - string key = excelWorksheet.Cells[1, i].GetCellValue(); - list.Add(new () { Name = key, Key = key }); + if (stateContainer.Source is not null) + { + using (ExcelPackage excelPackage = new(stateContainer.Source.Path)) + { + try + { + ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets[0]; + for (int i = 1; i <= excelWorksheet.Dimension?.End.Column; i++) + { + if (i % 3 == 1) + { + string key = excelWorksheet.Cells[1, i].GetCellValue(); + list.Add(new() { Name = key, Key = key }); + } } } - }catch{ } + catch { } + } } return list; } @@ -113,16 +147,23 @@ public void SetSource(Source source){ public IEnumerable ReadPrefabPrompts(string key){ ExcelPackage.LicenseContext = LicenseContext.NonCommercial; List list = new (); - using (ExcelPackage excelPackage = new (stateContainer.Source?.Path)){ - try { - ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets[1]; - for (int i = 1; i <= excelWorksheet?.Dimension?.End.Row; i++){ - string prompts = excelWorksheet.Cells[i, 1].GetCellValue(); - string name = excelWorksheet.Cells[i, 2].GetCellValue(); - string image = excelWorksheet.Cells[i, 3].GetCellValue(); - list.Add(new () { Name = name, Key = prompts, Image = image }); + if (stateContainer.Source is not null) + { + using (ExcelPackage excelPackage = new(stateContainer.Source.Path)) + { + try + { + ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets[1]; + for (int i = 1; i <= excelWorksheet.Dimension?.End.Row; i++) + { + string prompts = excelWorksheet.Cells[i, 1].GetCellValue(); + string name = excelWorksheet.Cells[i, 2].GetCellValue(); + string image = excelWorksheet.Cells[i, 3].GetCellValue(); + list.Add(new() { Name = name, Key = prompts, Image = image }); + } } - }catch{ } + catch { } + } } return list; } @@ -130,4 +171,6 @@ public IEnumerable ReadPrefabPrompts(string key){ public async Task> ReadPrefabPromptsAsync(string key){ return await Task.Run(() => { return ReadPrefabPrompts(key); }); } + + } diff --git a/AiPrompt/Shared/MainLayout.razor b/AiPrompt/Shared/MainLayout.razor index 1b21df8..1f5112a 100644 --- a/AiPrompt/Shared/MainLayout.razor +++ b/AiPrompt/Shared/MainLayout.razor @@ -1,15 +1,19 @@ @using AiPrompt.Data @using AiPrompt.Service +@using AiPrompt.Util @using BlazorComponent @inherits LayoutComponentBase + @inject IPromptService promptService +@inject ISourceService sourceService +@inject IConfigService configService @inject NavigationManager navigationManager @inject StateContainer stateContainer @implements IDisposable - +

AI-Prompt

@@ -36,44 +40,104 @@ - - mdi-magnify - + + + + mdi-cog + + + + + + 设置 + + + + + + + + + + (((((pussy)))))!!! + + + + + 关闭 + + + 保存 + + + + + - - - - @Body - - - + + @Body +
+ @code { private bool drawer = false; + private bool setting = false; + + private Config Config { get; set; } = new(); + private List Sources { get; set; } = new(); + private IEnumerable promps = new List(); + private StringNumber selected = 0; - public string QueryString { get; set; } - void Query(){ - stateContainer.Query = QueryString; + private string queryString; + public string QueryString{ + get => queryString; + set { + queryString = value; + stateContainer.Query = value; + } } - IEnumerable promps = new List(); + async void OpenSetting(){ + Config.SourcePath = await sourceService.GetSourcePathAsync(); + setting = !setting; + StateHasChanged(); + } + async void SaveSetting (){ + await configService.SaveConfig(Config); + Sources = await sourceService.AllSourceAsync(); + setting = false; + StateHasChanged(); + } //切换咒语书时拉取分类 - protected async void OnSourceChanged(){ + async void OnSourceChanged(){ promps = await promptService.CategoriesAsync(); StateHasChanged(); } - protected override void OnInitialized(){ + protected override async Task OnInitializedAsync() + { + Config.SourcePath = await sourceService.GetSourcePathAsync(); + Sources = await sourceService.AllSourceAsync(); + } + + protected override void OnInitialized() + { stateContainer.OnSourceChanged += OnSourceChanged; navigationManager.NavigateTo("prefab"); } @@ -81,6 +145,4 @@ public void Dispose(){ stateContainer.OnSourceChanged -= OnSourceChanged; } - - } \ No newline at end of file diff --git a/AiPrompt/Shared/SourceSelect.razor b/AiPrompt/Shared/SourceSelect.razor index 9188c24..69b0ab2 100644 --- a/AiPrompt/Shared/SourceSelect.razor +++ b/AiPrompt/Shared/SourceSelect.razor @@ -7,15 +7,16 @@ @bind-Value="Selected" ItemText="u => u.Name" ItemValue="u => u" - Label="Source"> + Label="咒语书"> @data.Item.Name - + @code { - List Sources{ get; set; } + [Parameter] + public List Sources { get; set; } = new(); private Source selected; public Source Selected @@ -26,11 +27,21 @@ sourceService.SetSource(value); } } - protected override async Task OnInitializedAsync(){ - IEnumerable sources = await sourceService.AllSourceAsync(); - Sources = sources.ToList(); - Selected = Sources?[0]; - } + void SetDefault(){ + if (Sources?.Count > 0) + { + Selected = Sources[0]; + } + } + protected override Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + SetDefault(); + } + return base.OnAfterRenderAsync(firstRender); + } + } diff --git "a/AiPrompt/Sources/\350\265\233\345\215\232\350\220\250\346\273\241\345\277\205\344\277\256\357\274\232\344\270\216AI\345\257\271\350\257\235\347\232\204tag\351\233\206.xlsx" "b/AiPrompt/Sources/\350\265\233\345\215\232\350\220\250\346\273\241\345\277\205\344\277\256\357\274\232\344\270\216AI\345\257\271\350\257\235\347\232\204tag\351\233\206.xlsx" deleted file mode 100644 index a9ce584..0000000 Binary files "a/AiPrompt/Sources/\350\265\233\345\215\232\350\220\250\346\273\241\345\277\205\344\277\256\357\274\232\344\270\216AI\345\257\271\350\257\235\347\232\204tag\351\233\206.xlsx" and /dev/null differ diff --git "a/AiPrompt/Sources/\350\265\233\345\215\232\350\220\250\346\273\241\345\277\205\344\277\256\357\274\232\344\270\216AI\345\257\271\350\257\235\347\232\204tag\351\233\2062.xlsx" "b/AiPrompt/Sources/\350\265\233\345\215\232\350\220\250\346\273\241\345\277\205\344\277\256\357\274\232\344\270\216AI\345\257\271\350\257\235\347\232\204tag\351\233\2062.xlsx" deleted file mode 100644 index 30f7a85..0000000 Binary files "a/AiPrompt/Sources/\350\265\233\345\215\232\350\220\250\346\273\241\345\277\205\344\277\256\357\274\232\344\270\216AI\345\257\271\350\257\235\347\232\204tag\351\233\2062.xlsx" and /dev/null differ diff --git a/AiPrompt/Util/Db.cs b/AiPrompt/Util/Db.cs new file mode 100644 index 0000000..64bbe6d --- /dev/null +++ b/AiPrompt/Util/Db.cs @@ -0,0 +1,33 @@ +using AiPrompt.Data; +using SQLite; + +namespace AiPrompt.Util; + +public class Db +{ + private SQLiteAsyncConnection Database; + async Task Init() + { + if (Database is not null) + return; + + Database = new SQLiteAsyncConnection(DbConstants.DatabasePath, DbConstants.Flags); + var result = await Database.CreateTableAsync(); + } + + public async Task GetAsync() where T : BaseModel, new() + { + await Init(); + return await Database.Table().FirstOrDefaultAsync(); + } + + public async Task SaveAsync(T t) where T : BaseModel,new() + { + await Init(); + var exsist = await Database.Table().FirstOrDefaultAsync(); + if (string.Equals(t?.Id,exsist?.Id)) + return await Database.UpdateAsync(t); + else + return await Database.InsertAsync(t); + } +} diff --git a/AiPrompt/Util/DbConstants.cs b/AiPrompt/Util/DbConstants.cs new file mode 100644 index 0000000..503f019 --- /dev/null +++ b/AiPrompt/Util/DbConstants.cs @@ -0,0 +1,18 @@ + +namespace AiPrompt.Util; + +public static class DbConstants +{ + public const string DatabaseFilename = "AiPrompt.db3"; + + public const SQLite.SQLiteOpenFlags Flags = + // open the database in read/write mode + SQLite.SQLiteOpenFlags.ReadWrite | + // create the database if it doesn't exist + SQLite.SQLiteOpenFlags.Create | + // enable multi-threaded database access + SQLite.SQLiteOpenFlags.SharedCache; + + public static string DatabasePath => + Path.Combine(FileSystem.AppDataDirectory, DatabaseFilename); +} \ No newline at end of file diff --git a/AiPrompt/Service/StateContainer.cs b/AiPrompt/Util/StateContainer.cs similarity index 58% rename from AiPrompt/Service/StateContainer.cs rename to AiPrompt/Util/StateContainer.cs index b26c89a..bd633e0 100644 --- a/AiPrompt/Service/StateContainer.cs +++ b/AiPrompt/Util/StateContainer.cs @@ -1,15 +1,10 @@ using AiPrompt.Data; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace AiPrompt.Service; +namespace AiPrompt.Util; public class StateContainer { - private string? query; + private string query; public string Query { @@ -20,10 +15,10 @@ public string Query OnQueryChanged?.Invoke(); } } - public event Action? OnQueryChanged; + public event Action OnQueryChanged; - private Source? source; + private Source source; public Source Source { get => source; @@ -33,6 +28,6 @@ public Source Source OnSourceChanged?.Invoke(); } } - public event Action? OnSourceChanged; + public event Action OnSourceChanged; } \ No newline at end of file diff --git a/AiPrompt/wwwroot/favicon.ico b/AiPrompt/wwwroot/favicon.ico index 63e859b..a4b7a41 100644 Binary files a/AiPrompt/wwwroot/favicon.ico and b/AiPrompt/wwwroot/favicon.ico differ diff --git a/AiPrompt/wwwroot/index.html b/AiPrompt/wwwroot/index.html index 13cd617..3ca7b46 100644 --- a/AiPrompt/wwwroot/index.html +++ b/AiPrompt/wwwroot/index.html @@ -5,9 +5,7 @@ AiPrompt - -