Use External Python File Instead Of Embedded,

This commit is contained in:
bmgjet 2024-12-25 01:26:31 +13:00 committed by GitHub
parent cd94663283
commit 94e97027ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 186 additions and 19 deletions

View File

@ -80,6 +80,8 @@
this.Loralbl = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.VideoRes = new System.Windows.Forms.ComboBox();
this.timer3 = new System.Windows.Forms.Timer(this.components);
this.Updates = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.panel1.SuspendLayout();
@ -271,10 +273,15 @@
//
this.AspectRatio.FormattingEnabled = true;
this.AspectRatio.Items.AddRange(new object[] {
"21:9",
"16:9",
"9:16",
"4:3",
"1:1"});
"3:2",
"1:1",
"2:3",
"3:4",
"9:16",
"9:21"});
this.AspectRatio.Location = new System.Drawing.Point(93, 372);
this.AspectRatio.Margin = new System.Windows.Forms.Padding(2);
this.AspectRatio.MaxLength = 5;
@ -556,6 +563,7 @@
//
// panel1
//
this.panel1.Controls.Add(this.Updates);
this.panel1.Controls.Add(this.Weighttxt);
this.panel1.Controls.Add(this.Weightlbl);
this.panel1.Controls.Add(this.LoraButton);
@ -669,9 +677,15 @@
this.VideoRes.FormattingEnabled = true;
this.VideoRes.Items.AddRange(new object[] {
"auto",
"576, 448",
"512, 288",
"720, 540"});
"1920, 1080",
"1366, 768",
"1280, 720",
"1024, 768",
"768, 768",
"720, 540",
"854, 480",
"640, 360 ",
"512, 512"});
this.VideoRes.Location = new System.Drawing.Point(445, 372);
this.VideoRes.Margin = new System.Windows.Forms.Padding(2);
this.VideoRes.MaxLength = 8;
@ -681,6 +695,21 @@
this.VideoRes.Text = "auto";
this.VideoRes.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.VideoRes_KeyPress);
//
// timer3
//
this.timer3.Interval = 5000;
this.timer3.Tick += new System.EventHandler(this.timer3_Tick);
//
// Updates
//
this.Updates.AutoSize = true;
this.Updates.Location = new System.Drawing.Point(382, 449);
this.Updates.Name = "Updates";
this.Updates.Size = new System.Drawing.Size(150, 17);
this.Updates.TabIndex = 48;
this.Updates.Text = "Check For Model Updates";
this.Updates.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -761,6 +790,8 @@
private System.Windows.Forms.Button LoraButton;
private System.Windows.Forms.TextBox Loratxt;
private System.Windows.Forms.Label Loralbl;
private System.Windows.Forms.Timer timer3;
private System.Windows.Forms.CheckBox Updates;
}
}

View File

@ -1,9 +1,19 @@
using System;
/*
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
@ -16,23 +26,33 @@ namespace Ruyi_GUI
public partial class Form1 : Form
{
public static List<string> LogMessages = new List<string>();
public string PythonCode;
public string[] PythonCode;
public bool DoingJobs = false;
public bool Not100 = true;
public Form1()
{
InitializeComponent();
PythonCode = Encoding.UTF8.GetString(Convert.FromBase64String(Decompress(Convert.FromBase64String("xRprb+M28nuA/AeeroClrqrdpO0eEEAf0tjZGhdvgiS3/ZAzBMaibG5kUadHNmng/34zJCVRD9vpXoAL0CbivIfD4cxw+ToVWUFEfnjA1Z+FyBarw4MoE2tyNb0genm6pkuml0MeRWXOsrwC2pMyZtmY54uMFexmsWIhLrhErp8mC5YXGY37COOr2Y2IH1k2K+OC5wVLDeKrz+OZ8TkeT5tPR6si1mxJFyKJKlUuceEMFjQCyE3ySGRrQ92zi+mVtOcqE6BaLoA7rn3hORfJTIQs/oMXK4B+ZYsCljSvnEagfQL4uSfdVDGMBQ2DiMeM0Fx9GKiaeFUulzxZRnTBglV5X5HmCU3zlSiCUHxLkFSjZ+Uz90JaUO++XDywAjiuUzC8oju9uZqc3QbXp7fTy+DXo2OXLAFpEYscfB1kFNQ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2iQ15tN2x2d3J7SEi33t3lUH4eKWhJh+sWUhC4++uiAi48+Nl41NZy3orDLpNneTubwevEZRDFddoPZKFW8FQ9DqNAWFEqTKhR6U8nhM7GPzQetXWdYirOt8dXs3btquJUIONqBWTfueHbpFXDDZe2oZjeSJ3pYDfn8s12N4Vejt9eAnO7RYfsL1Zsqgw9a2zVpPXe9qVzsJHYEg9lnfJfcOmJNth1BGKtLBi01hRKtqtM+VQu2miE73pomJeQAnMrb+D+0yqxQ32qqLEtHaDi1IokIlhneNtpLrWcYHy9ku7X0/n1zTKFt8dY84cE9LaDLqPrbH/dhOKS+STTXv/nkSGXbI33ZJ/VzkWt+qDGS0Xtozww+ZjX52tXlJvxhyvXND3z6qpOsb7dSo1MX/JhUg/q2dPXf+jEBcu2fPLXlpS1HsPrlAgr5u7njEgOg72IFcczGoKn4muc8Y5u3CdfXgi46pSXGpN3oRqEvW6fF4FS3N9ycuz26XSPdrfPOAT7DY92BoedeHbbz6E0KTV71zHCXQ7rz0F0Mdnpm26x0v0Y98/qT09drtZ3ZTl91skLr2DRYK+NJza9qiwasiowKrIqdBlqnSAmtv0yMkocU7itIrVQG9yJamoaX64AnEcuYxJFvnljvwe+uJaTWwswzRi+BHqgw/X7+GRqhSczmsxozOZ56S/9/5A/zHwS8LoPUD/XqtgMe1awFLhC8Ve3eQ75qndtkkM5HI60TMFjTBwb0ud3Cgpz8BBVYIB587MeAT/efHtgqjbmkJ9QlUZr7x784/wU="))));
if (File.Exists("Config.cfg")) { LoadSettings(File.ReadAllText("Config.cfg")); }
else { SaveSettings(); }
if(!File.Exists("environment.bat"))
{
MessageBox.Show("environment.bat file missing, Is this exe being ran from Forge Install folder?","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
if (!Directory.Exists("Ruyi-Models"))
{
MessageBox.Show("Missing Ruyi-Models Folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if(!File.Exists(Path.Combine("Ruyi-Models", "predict_i2v.py")))
{
MessageBox.Show("Missing predict_i2v.py", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
PythonCode = File.ReadAllLines(Path.Combine("Ruyi-Models", "predict_i2v.py"));
}
private string SettingsString() { return Img1.Text + "|" + Img2.Text + "|" + VideoOut.Text + "|" + FrameRate.Text + "|" + AspectRatio.Text + "|" + Resolution.Text + "|" + Direction.Text + "|" + Motion.Text + "|" + GPUOffload.Text + "|" + LowMemoryMode.Checked + "|" + Steps.Text + "|" + Cfg.Text + "|" + Seed.Text + "|" + Scheduler.Text + "|" + VideoRes.Text + "|" + Loratxt.Text + "|" + Weighttxt.Text; }
private string SettingsString() { return Img1.Text + "|" + Img2.Text + "|" + VideoOut.Text + "|" + FrameRate.Text + "|" + AspectRatio.Text + "|" + Resolution.Text + "|" + Direction.Text + "|" + Motion.Text + "|" + GPUOffload.Text + "|" + LowMemoryMode.Checked + "|" + Steps.Text + "|" + Cfg.Text + "|" + Seed.Text + "|" + Scheduler.Text + "|" + VideoRes.Text + "|" + Loratxt.Text + "|" + Weighttxt.Text + "|" + Updates.Checked; }
private void SaveSettings() { File.WriteAllText("Config.cfg", SettingsString()); }
@ -58,6 +78,7 @@ namespace Ruyi_GUI
VideoRes.Text = SSettings[14];
Loratxt.Text = SSettings[15];
Weighttxt.Text = SSettings[16];
Updates.Checked = bool.Parse(SSettings[17]);
}
catch
{
@ -107,16 +128,19 @@ namespace Ruyi_GUI
private void LogFiltered(string message)
{
if (string.IsNullOrEmpty(message)) { return; }
if (string.IsNullOrEmpty(message) || message.Contains(" attn_output = torch.nn.functional.scaled_dot_product_attention(")) { return; }
LogMessages.Add(message);
if (message.Contains("%")) { AppendTextBox(message); }
if (message.Contains("%") || message.StartsWith("Fetching ")) { AppendTextBox(message); }
if (message.StartsWith("Fetching ")) { return; }
if (message.Contains("100%") && Not100) { Not100 = false; return; }
if (message.Contains("100%"))
{
Not100 = true;
timer3.Enabled = false;
AppendTextBox("Saving Mp4...");
GenerateButton.BeginInvoke(new Action(() => { GenerateButton.Enabled = true; }));
panel1.BeginInvoke(new Action(() => { panel1.Enabled = true; }));
LogMessages.Add("Finished Generation @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
if (DoingJobs)
{
while (!File.Exists(VideoOut.Text)) { Thread.Sleep(1000); }
@ -154,18 +178,115 @@ namespace Ruyi_GUI
}
}
private void ExecuteCommand()
private string ParsePythonCode()
{
if (!Directory.Exists("Ruyi-Models"))
{
MessageBox.Show("Missing Ruyi-Models Folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string code = "";
string Image2 = string.IsNullOrEmpty(Img2.Text) ? "None" : @"""" + Img2.Text.Replace(@"\", @"\\") + @"""";
string Lora = string.IsNullOrEmpty(Loratxt.Text) ? "None" : @"""" + Loratxt.Text.Replace(@"\", @"\\") + @"""";
string CallCode = PythonCode.Replace("{$IMAGE1}", Img1.Text.Replace(@"\", @"\\")).Replace("{$IMAGE2}", Image2).Replace("{$VIDEO}", VideoOut.Text.Replace(@"\", @"\\")).Replace("{$FRAMES}", FrameRate.Text).Replace("{$RES}", Resolution.Text).Replace("{$ASPECT}", AspectRatio.Text).Replace("{$MOTION}", Motion.Text).Replace("{$DIRECTION}", Direction.Text).Replace("{$STEPS}", Steps.Text).Replace("{$CFG}", Cfg.Text).Replace("{$SCHEDULER}", Scheduler.Text).Replace("{$LOWMEM}", LowMemoryMode.Checked.ToString()).Replace("{$OFFLOAD}", GPUOffload.Text).Replace("{$SEED}", Seed.Text).Replace("video_size = None", "video_size = " + VideoRes.Text.Replace("auto","None")).Replace("lora_path = None", "lora_path = " + Lora).Replace("lora_weight = 1.0", "lora_weight = " + Weighttxt.Text);
foreach (string line in PythonCode)
{
if(line.StartsWith("start_image_path = "))
{
code += @"start_image_path = """ + Img1.Text.Replace(@"\", @"\\") + @""""+ System.Environment.NewLine;
continue;
}
if (line.StartsWith("end_image_path = "))
{
code += "end_image_path = " + Image2.Replace(@"\", @"\\") + System.Environment.NewLine;
continue;
}
if (line.StartsWith("output_video_path = "))
{
code += @"output_video_path = """ + VideoOut.Text.Replace(@"\", @"\\") + @"""" + System.Environment.NewLine;
continue;
}
if (line.StartsWith("video_length = "))
{
code += @"video_length = " + FrameRate.Text + System.Environment.NewLine;
continue;
}
if (line.StartsWith("base_resolution = "))
{
code += @"base_resolution = " + Resolution.Text + System.Environment.NewLine;
continue;
}
if (line.StartsWith("video_size = "))
{
code += @"video_size = " + VideoRes.Text.Replace("auto","None") + System.Environment.NewLine;
continue;
}
if (line.StartsWith("aspect_ratio = "))
{
code += @"aspect_ratio = """ + AspectRatio.Text + @"""" + System.Environment.NewLine;
continue;
}
if (line.StartsWith("motion = "))
{
code += @"motion = """ + Motion.Text + @"""" + System.Environment.NewLine;
continue;
}
if (line.StartsWith("camera_direction = "))
{
code += @"camera_direction = """ + Direction.Text + @"""" + System.Environment.NewLine;
continue;
}
if (line.StartsWith("steps = "))
{
code += @"steps = " + Steps.Text + System.Environment.NewLine;
continue;
}
if (line.StartsWith("cfg = "))
{
code += @"cfg = " + Cfg.Text + System.Environment.NewLine;
continue;
}
if (line.StartsWith("scheduler_name = "))
{
code += @"scheduler_name = """ + Scheduler.Text + @"""" + System.Environment.NewLine;
continue;
}
if (line.StartsWith("low_gpu_memory_mode = "))
{
code += @"low_gpu_memory_mode = " + LowMemoryMode.Checked.ToString() + System.Environment.NewLine;
continue;
}
if (line.StartsWith("gpu_offload_steps = "))
{
code += @"gpu_offload_steps = " + GPUOffload.Text + System.Environment.NewLine;
continue;
}
if (line.StartsWith("seed = "))
{
code += @"seed = " + Seed.Text + System.Environment.NewLine;
continue;
}
if (line.StartsWith("lora_path = "))
{
code += @"lora_path = " + Lora + System.Environment.NewLine;
continue;
}
if (line.StartsWith("lora_weight = "))
{
code += @"lora_weight = " + Weighttxt.Text + System.Environment.NewLine;
continue;
}
if (line.StartsWith("auto_update = "))
{
code += @"auto_update = " + Updates.Checked.ToString() + System.Environment.NewLine;
continue;
}
code += line + System.Environment.NewLine;
}
return code;
}
private void ExecuteCommand()
{
string CallCode = ParsePythonCode();
if (string.IsNullOrEmpty(CallCode)) { MessageBox.Show("Bad Python Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
File.WriteAllText(Path.Combine("Ruyi-Models", "i2v.py"), CallCode);
if (File.Exists(VideoOut.Text)) { File.Move(VideoOut.Text, VideoOut.Text.Replace(".mp4", "-" + GetTimestamp() + ".mp4")); }
LogMessages.Add("Starting Generation: ["+FrameRate.Text + "-"+ Resolution.Text +"] " + Path.GetFileName(Img1.Text) + " @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Task.Run(() =>
{
GenerateButton.BeginInvoke(new Action(() => { GenerateButton.Enabled = false; }));
@ -184,6 +305,7 @@ namespace Ruyi_GUI
process.WaitForExit();
process.Close();
});
timer3.Enabled = true;
}
private string SelectImageButton()
@ -266,7 +388,7 @@ namespace Ruyi_GUI
if (string.IsNullOrEmpty(Scheduler.Text)) { MessageBox.Show("Scheduler Can't Be Null", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
if (string.IsNullOrEmpty(Weighttxt.Text)) { MessageBox.Show("Lora Weight Can't Be Null", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
if(!AspectRatio.Text.Contains(":")){ MessageBox.Show("Aspect Ratio Not Valid Format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
if (!VideoRes.Text.Contains(", ") && !VideoRes.Text.Contains("None")) { MessageBox.Show("Mp4 Resolution Not Valid Format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
if (!VideoRes.Text.Contains(", ") && !VideoRes.Text.Contains("None") && !VideoRes.Text.Contains("auto")) { MessageBox.Show("Mp4 Resolution Not Valid Format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; }
return true;
}
@ -394,5 +516,16 @@ namespace Ruyi_GUI
if (dialog.ShowDialog() == DialogResult.OK) { Loratxt.Text = dialog.FileName; }
dialog.Dispose();
}
private void timer3_Tick(object sender, EventArgs e)
{
Process[] processes = Process.GetProcesses();
bool isPythonRunning = processes.Any(p => p.ProcessName.Equals("python", StringComparison.OrdinalIgnoreCase));
if (!isPythonRunning)
{
timer3.Enabled = false;
MessageBox.Show("python.exe is not running. Maybe it crashed, Please check the log.txt","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
}

View File

@ -123,6 +123,9 @@
<metadata name="timer2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>105, 17</value>
</metadata>
<metadata name="timer3.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>193, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>