mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-25 04:39:25 +01:00
Server manager with ping check, better error handling for missing model files
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Flowframes.Data
|
||||
public class ModelCollection
|
||||
{
|
||||
public AI ai;
|
||||
public List<ModelInfo> models;
|
||||
public List<ModelInfo> models = new List<ModelInfo>();
|
||||
|
||||
public class ModelInfo
|
||||
{
|
||||
@@ -40,8 +40,15 @@ namespace Flowframes.Data
|
||||
}
|
||||
}
|
||||
|
||||
public ModelCollection(AI ai)
|
||||
{
|
||||
this.ai = ai;
|
||||
}
|
||||
|
||||
public ModelCollection(AI ai, string jsonContentOrPath)
|
||||
{
|
||||
this.ai = ai;
|
||||
|
||||
if (IoUtils.IsPathValid(jsonContentOrPath) && File.Exists(jsonContentOrPath))
|
||||
jsonContentOrPath = File.ReadAllText(jsonContentOrPath);
|
||||
|
||||
|
||||
55
Code/Data/Servers.cs
Normal file
55
Code/Data/Servers.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flowframes.Data
|
||||
{
|
||||
class Servers
|
||||
{
|
||||
public static Server hetznerEu = new Server { host = "nmkd-hz.de", pattern = "https://dl.*" };
|
||||
public static Server contaboUs = new Server { host = "209.126.5.164", pattern = "http://*/dl" };
|
||||
|
||||
public static List<Server> serverList = new List<Server> { hetznerEu, contaboUs };
|
||||
|
||||
public static Server closestServer = serverList[0];
|
||||
|
||||
public class Server
|
||||
{
|
||||
public string host = "";
|
||||
public string pattern = "*";
|
||||
|
||||
public string GetUrl ()
|
||||
{
|
||||
return pattern.Replace("*", host);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task Init ()
|
||||
{
|
||||
Dictionary<string[], long> serversPings = new Dictionary<string[], long>();
|
||||
|
||||
foreach(Server server in serverList)
|
||||
{
|
||||
try
|
||||
{
|
||||
Ping p = new Ping();
|
||||
PingReply replyEur = p.Send(server.host, 2000);
|
||||
serversPings[new string[] { server.host, server.pattern }] = replyEur.RoundtripTime;
|
||||
Logger.Log($"[Servers] Ping to {server.host}: {replyEur.RoundtripTime} ms", true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log($"[Servers] Failed to ping {server.host}: {e.Message}", true);
|
||||
serversPings[new string[] { server.host, server.pattern }] = 10000;
|
||||
}
|
||||
}
|
||||
|
||||
var closest = serversPings.Aggregate((l, r) => l.Value < r.Value ? l : r);
|
||||
Logger.Log($"[Servers] Closest Server: {closest.Key[0]} ({closest.Value} ms)", true);
|
||||
closestServer = new Server { host = closest.Key[0], pattern = closest.Key[1] };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,6 +336,7 @@
|
||||
<Compile Include="Data\AudioTrack.cs" />
|
||||
<Compile Include="Data\Filetypes.cs" />
|
||||
<Compile Include="Data\ModelCollection.cs" />
|
||||
<Compile Include="Data\Servers.cs" />
|
||||
<Compile Include="Data\VidExtraData.cs" />
|
||||
<Compile Include="Data\Fraction.cs" />
|
||||
<Compile Include="Data\InterpSettings.cs" />
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace Flowframes
|
||||
Task.Run(() => Updater.AsyncUpdateCheck());
|
||||
Task.Run(() => GetWebInfo.LoadNews(newsLabel));
|
||||
Task.Run(() => GetWebInfo.LoadPatronListCsv(patronsLabel));
|
||||
Task.Run(() => Servers.Init());
|
||||
await Python.CheckCompression();
|
||||
await StartupChecks.SymlinksCheck();
|
||||
}
|
||||
@@ -322,7 +323,14 @@ namespace Flowframes
|
||||
|
||||
public ModelCollection.ModelInfo GetModel(AI currentAi)
|
||||
{
|
||||
return AiModels.GetModels(currentAi).models[aiModel.SelectedIndex];
|
||||
try
|
||||
{
|
||||
return AiModels.GetModels(currentAi).models[aiModel.SelectedIndex];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Interpolate.OutMode GetOutMode()
|
||||
|
||||
@@ -278,7 +278,6 @@ namespace Flowframes.IO
|
||||
if (key == Key.ncnnThreads) return WriteDefault(key, "1");
|
||||
if (key == Key.dainNcnnTilesize) return WriteDefault(key, "768");
|
||||
// Debug / Other / Experimental
|
||||
if (key == Key.mdlBaseUrl) return WriteDefault(key, "https://dl.nmkd-hz.de/flowframes/mdl/");
|
||||
if (key == Key.ffEncPreset) return WriteDefault(key, "medium");
|
||||
if (key == Key.sbsRunPreviousStepIfNeeded) return WriteDefault(key, "true");
|
||||
|
||||
@@ -358,7 +357,6 @@ namespace Flowframes.IO
|
||||
maxFps,
|
||||
maxFpsMode,
|
||||
maxVidHeight,
|
||||
mdlBaseUrl,
|
||||
minOutVidLength,
|
||||
minVidLength,
|
||||
mp4Enc,
|
||||
|
||||
@@ -17,7 +17,9 @@ namespace Flowframes.IO
|
||||
|
||||
static string GetMdlUrl (string ai, string relPath)
|
||||
{
|
||||
string baseUrl = Config.Get(Config.Key.mdlBaseUrl);
|
||||
string custServer = Config.Get(Config.Key.customServer);
|
||||
string server = custServer.Trim().Length > 3 ? custServer : Servers.closestServer.GetUrl();
|
||||
string baseUrl = $"{server}/flowframes/mdl/";
|
||||
return Path.Combine(baseUrl, ai.ToLower(), relPath);
|
||||
}
|
||||
|
||||
@@ -111,6 +113,9 @@ namespace Flowframes.IO
|
||||
{
|
||||
dynamic data = JsonConvert.DeserializeObject(json);
|
||||
|
||||
if (data == null)
|
||||
return modelFiles;
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
string dirString = ((string)item.dir).Replace(@"\", @"/");
|
||||
|
||||
@@ -16,6 +16,13 @@ namespace Flowframes.Main
|
||||
{
|
||||
string pkgPath = Path.Combine(Paths.GetPkgPath(), ai.pkgDir);
|
||||
string modelsFile = Path.Combine(pkgPath, "models.json");
|
||||
|
||||
if (!File.Exists(modelsFile))
|
||||
{
|
||||
Logger.Log($"Error: File models.json is missing for {ai.aiName}, can't load AI models for this implementation!");
|
||||
return new ModelCollection(ai);
|
||||
}
|
||||
|
||||
ModelCollection modelCollection = new ModelCollection(ai, modelsFile);
|
||||
|
||||
foreach (string customModel in GetCustomModels(ai))
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Flowframes
|
||||
Program.initialRun = false;
|
||||
Program.mainForm.SetWorking(true);
|
||||
if (!Utils.InputIsValid(current.inPath, current.outPath, current.outFps, current.interpFactor, current.outMode)) return; // General input checks
|
||||
if (!Utils.CheckAiAvailable(current.ai)) return; // Check if selected AI pkg is installed
|
||||
if (!Utils.CheckAiAvailable(current.ai, current.model)) return; // Check if selected AI pkg is installed
|
||||
if (!ResumeUtils.resumeNextRun && !Utils.CheckDeleteOldTempFolder()) return; // Try to delete temp folder if an old one exists
|
||||
if (!Utils.CheckPathValid(current.inPath)) return; // Check if input path/file is valid
|
||||
if (!(await Utils.CheckEncoderValid())) return; // Check NVENC compat
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Flowframes.Main
|
||||
|
||||
public static async Task InterpolateStep()
|
||||
{
|
||||
if (!InterpolateUtils.CheckAiAvailable(current.ai)) return;
|
||||
if (!InterpolateUtils.CheckAiAvailable(current.ai, current.model)) return;
|
||||
|
||||
current.framesFolder = Path.Combine(current.tempFolder, Paths.framesDir);
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace Flowframes.Main
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckAiAvailable(AI ai)
|
||||
public static bool CheckAiAvailable(AI ai, ModelCollection.ModelInfo model)
|
||||
{
|
||||
if (IoUtils.GetAmountOfFiles(Path.Combine(Paths.GetPkgPath(), ai.pkgDir), true) < 1)
|
||||
{
|
||||
@@ -147,6 +147,13 @@ namespace Flowframes.Main
|
||||
return false;
|
||||
}
|
||||
|
||||
if (model == null || model.dir.Trim() == "")
|
||||
{
|
||||
ShowMessage("No valid AI model has been selected!", "Error");
|
||||
I.Cancel("No valid model selected.", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (I.current.ai.aiName.ToUpper().Contains("CUDA") && NvApi.gpuList.Count < 1)
|
||||
{
|
||||
ShowMessage("Warning: No Nvidia GPU was detected. CUDA might fall back to CPU!\n\nTry an NCNN implementation instead if you don't have an Nvidia GPU.", "Error");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -37,6 +37,9 @@ namespace Flowframes.Ui
|
||||
{
|
||||
ModelCollection modelCollection = AiModels.GetModels(ai);
|
||||
|
||||
if (modelCollection.models == null || modelCollection.models.Count < 1)
|
||||
return combox;
|
||||
|
||||
for (int i = 0; i < modelCollection.models.Count; i++)
|
||||
{
|
||||
ModelCollection.ModelInfo modelInfo = modelCollection.models[i];
|
||||
|
||||
Reference in New Issue
Block a user