-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save Models in baseModel subfolder #230
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,8 +505,23 @@ public static async Task<JObject> DoModelDownloadWS(Session session, WebSocket w | |
} | ||
try | ||
{ | ||
string outPath = $"{handler.FolderPaths[0]}/{name}.safetensors"; | ||
if (File.Exists(outPath)) | ||
string baseModel = ""; | ||
if (!string.IsNullOrWhiteSpace(metadata)) | ||
{ | ||
JObject metadataObj = JObject.Parse(metadata); | ||
baseModel = metadataObj["modelspec.baseModel"]?.ToString() ?? ""; | ||
} | ||
string modelOutPath; | ||
if (!string.IsNullOrWhiteSpace(baseModel) && session.User.Settings.GroupDownloadedModelsByBaseType) | ||
{ | ||
modelOutPath = $"{handler.FolderPaths[0]}/{baseModel}/{name}.safetensors"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is just editing the folder path, it should be implemented in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I get access to user settings from the js side? On the C# side I could just reach for the user session pretty easily. I know the JS side must have a helper method for that as well, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah |
||
} | ||
else | ||
{ | ||
modelOutPath = $"{handler.FolderPaths[0]}/{name}.safetensors"; | ||
} | ||
modelOutPath = Utilities.StrictFilenameClean(modelOutPath); | ||
if (File.Exists(modelOutPath)) | ||
{ | ||
await ws.SendJson(new JObject() { ["error"] = "Model at that save path already exists." }, API.WebsocketTimeout); | ||
return null; | ||
|
@@ -516,7 +531,7 @@ public static async Task<JObject> DoModelDownloadWS(Session session, WebSocket w | |
{ | ||
File.Delete(tempPath); | ||
} | ||
Directory.CreateDirectory(Path.GetDirectoryName(outPath)); | ||
Directory.CreateDirectory(Path.GetDirectoryName(modelOutPath)); | ||
using CancellationTokenSource canceller = new(); | ||
Task downloading = Utilities.DownloadFile(url, tempPath, (progress, total, perSec) => | ||
{ | ||
|
@@ -556,10 +571,20 @@ public static async Task<JObject> DoModelDownloadWS(Session session, WebSocket w | |
} | ||
}); | ||
await downloading; | ||
File.Move(tempPath, outPath); | ||
File.Move(tempPath, modelOutPath); | ||
if (!string.IsNullOrWhiteSpace(metadata)) | ||
{ | ||
File.WriteAllText($"{handler.FolderPaths[0]}/{name}.json", metadata); | ||
string metadataOutPath; | ||
if (!string.IsNullOrWhiteSpace(baseModel) && session.User.Settings.GroupDownloadedModelsByBaseType) | ||
{ | ||
metadataOutPath = $"{handler.FolderPaths[0]}/{baseModel}/{name}.json"; | ||
} | ||
else | ||
{ | ||
metadataOutPath = $"{handler.FolderPaths[0]}/{name}.json"; | ||
} | ||
metadataOutPath = Utilities.StrictFilenameClean(metadataOutPath); | ||
File.WriteAllText(metadataOutPath, metadata); | ||
} | ||
await ws.SendJson(new JObject() { ["success"] = true }, API.WebsocketTimeout); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3x minor doc nits:
.
at end of the sentenceModel Downloader utility
\nFor example, SDXL models will be placed automatically into an
SDXL/` directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it