2021-08-23 16:50:18 +02:00
|
|
|
|
using Flowframes.Data;
|
|
|
|
|
|
using Flowframes.IO;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.Main
|
|
|
|
|
|
{
|
|
|
|
|
|
class AiModels
|
|
|
|
|
|
{
|
|
|
|
|
|
public static ModelCollection GetModels (AI ai)
|
|
|
|
|
|
{
|
2022-05-31 22:17:22 +02:00
|
|
|
|
string pkgPath = Path.Combine(Paths.GetPkgPath(), ai.PkgDir);
|
2021-08-23 16:50:18 +02:00
|
|
|
|
string modelsFile = Path.Combine(pkgPath, "models.json");
|
2021-08-31 15:57:48 +02:00
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(modelsFile))
|
|
|
|
|
|
{
|
2024-06-24 11:36:43 +02:00
|
|
|
|
Logger.Log($"Error: '{modelsFile}' is missing for {ai.NameInternal}, can't load AI models for this implementation!", true);
|
2021-08-31 15:57:48 +02:00
|
|
|
|
return new ModelCollection(ai);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-23 16:50:18 +02:00
|
|
|
|
ModelCollection modelCollection = new ModelCollection(ai, modelsFile);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (string customModel in GetCustomModels(ai))
|
|
|
|
|
|
{
|
|
|
|
|
|
string name = customModel.Remove("_alpha").Remove("_custom");
|
|
|
|
|
|
bool alpha = customModel.Contains("_alpha");
|
2022-09-19 13:43:29 +02:00
|
|
|
|
modelCollection.Models.Add(new ModelCollection.ModelInfo() { Ai = ai, Name = name, Desc = "Custom Model", Dir = customModel, SupportsAlpha = alpha, IsDefault = false });
|
2021-08-23 16:50:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return modelCollection;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<string> GetCustomModels(AI ai)
|
|
|
|
|
|
{
|
2022-05-31 22:17:22 +02:00
|
|
|
|
string pkgPath = Path.Combine(Paths.GetPkgPath(), ai.PkgDir);
|
2021-08-23 16:50:18 +02:00
|
|
|
|
List<string> custModels = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (DirectoryInfo dir in new DirectoryInfo(pkgPath).GetDirectories())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dir.Name.EndsWith("_custom") && Regex.IsMatch(dir.Name, @"^[a-zA-Z0-9_]+$"))
|
|
|
|
|
|
custModels.Add(dir.Name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return custModels;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ModelCollection.ModelInfo GetModelByName(AI ai, string modelName)
|
|
|
|
|
|
{
|
|
|
|
|
|
ModelCollection modelCollection = GetModels(ai);
|
|
|
|
|
|
|
2022-07-27 15:18:37 +02:00
|
|
|
|
foreach(ModelCollection.ModelInfo model in modelCollection.Models)
|
2021-08-23 16:50:18 +02:00
|
|
|
|
{
|
2022-07-27 15:18:37 +02:00
|
|
|
|
if (model.Name == modelName)
|
2021-08-23 16:50:18 +02:00
|
|
|
|
return model;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ModelCollection.ModelInfo GetModelByDir(AI ai, string dirName)
|
|
|
|
|
|
{
|
|
|
|
|
|
ModelCollection modelCollection = GetModels(ai);
|
|
|
|
|
|
|
2022-07-27 15:18:37 +02:00
|
|
|
|
foreach (ModelCollection.ModelInfo model in modelCollection.Models)
|
2021-08-23 16:50:18 +02:00
|
|
|
|
{
|
2022-07-27 15:18:37 +02:00
|
|
|
|
if (model.Dir == dirName)
|
2021-08-23 16:50:18 +02:00
|
|
|
|
return model;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|