-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit b8c0101 Author: Byron Mallett <[email protected]> Date: Mon Jun 26 00:23:31 2023 +1200 Finished LoRA and model download support via browser widgets - Added huggingface web widget - Added style model class inheriting from the base model to differentiate between checkpoint and lora models. - Renamed plugin models to BaseModels and removed pre-style models that aren't base models. commit e984f4d Author: Byron Mallett <[email protected]> Date: Sat Jun 24 23:56:58 2023 +1200 Adding conversion tools to convert SD checkpoints into diffusers models Refactored civit.ai widget model downloading Made LoRA model asset extend the base model asset and added more properties commit a0c03bf Author: Byron Mallett <[email protected]> Date: Fri Jun 23 23:54:11 2023 +1200 Replaced HTTP module file download with Python Due to bug in CURL HTTP implementation that crashes with files over max int32 bytes. Eventual engine fix will be to replace TArray<uint8> Payload with TArray64<uint> and FThreadSafeCounter TotalBytesRead with std::atomic<int64> in CurlHttp.h commit 1575770 Author: Byron Mallett <[email protected]> Date: Thu Jun 22 21:54:42 2023 +1200 Adding browser for LORA and models commit 8e4590d Author: Byron Mallett <[email protected]> Date: Tue Jun 20 23:18:29 2023 +1200 Working LORA support commit e0667e4 Author: Byron Mallett <[email protected]> Date: Mon Jun 19 00:08:16 2023 +1200 Initial work on supporting LoRA models
- Loading branch information
Showing
70 changed files
with
762 additions
and
133 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+2.02 KB
StableDiffusionTools/Content/BaseModels/Diffusers_Runway1-5_Inpaint.uasset
Binary file not shown.
Binary file added
BIN
+2.09 KB
StableDiffusionTools/Content/BaseModels/Diffusers_StabilityAI2-0.uasset
Binary file not shown.
Binary file added
BIN
+2.05 KB
StableDiffusionTools/Content/BaseModels/Diffusers_StabilityAI2-0_Inpaint.uasset
Binary file not shown.
Binary file added
BIN
+2.03 KB
StableDiffusionTools/Content/BaseModels/Diffusers_StabilityAI2-0_base.uasset
Binary file not shown.
Binary file added
BIN
+2.09 KB
StableDiffusionTools/Content/BaseModels/Diffusers_StabilityAI2-1.uasset
Binary file not shown.
Binary file added
BIN
+2.03 KB
StableDiffusionTools/Content/BaseModels/Diffusers_StabilityAI2-1_base.uasset
Binary file not shown.
Binary file added
BIN
+2.04 KB
StableDiffusionTools/Content/BaseModels/Diffusers_StabilityAI2-1_depth.uasset
Binary file not shown.
Binary file added
BIN
+2 KB
StableDiffusionTools/Content/BaseModels/Diffusers_instructpix2pix.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-993 Bytes
(96%)
StableDiffusionTools/Content/Blueprints/A_ImagePlateCamera.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-2.76 KB
StableDiffusionTools/Content/Models/Diffusers_Runway1-5_Inpaint.uasset
Binary file not shown.
Binary file removed
BIN
-2.41 KB
StableDiffusionTools/Content/Models/Diffusers_StabilityAI2-0.uasset
Binary file not shown.
Binary file removed
BIN
-2.8 KB
StableDiffusionTools/Content/Models/Diffusers_StabilityAI2-0_Inpaint.uasset
Binary file not shown.
Binary file removed
BIN
-2.44 KB
StableDiffusionTools/Content/Models/Diffusers_StabilityAI2-1_768px.uasset
Binary file not shown.
Binary file removed
BIN
-2.44 KB
StableDiffusionTools/Content/Models/Diffusers_StabilityAI2-1_base.uasset
Binary file not shown.
Binary file removed
BIN
-2.85 KB
StableDiffusionTools/Content/Models/Diffusers_StabilityAI2-1_depth.uasset
Binary file not shown.
Binary file removed
BIN
-2.33 KB
StableDiffusionTools/Content/Models/Diffusers_WaifuDiffusion.uasset
Binary file not shown.
Binary file removed
BIN
-2.57 KB
StableDiffusionTools/Content/Models/Diffusers_instructpix2pix.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
265 changes: 198 additions & 67 deletions
265
StableDiffusionTools/Content/Python/bridges/DiffusersBridge.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import requests, re, pathlib, unreal | ||
|
||
response = requests.get(url, stream=True, allow_redirects=True) | ||
if response.status_code != 200: | ||
response.raise_for_status() # Will only raise for 4xx codes, so... | ||
print(f"Request to {url} returned status code {r.status_code}") | ||
downloader.fail_game_thread(0) | ||
file_size = int(response.headers.get('Content-Length', 0)) | ||
desc = "(Unknown total file size)" if file_size == 0 else "" | ||
|
||
url_filename = response.headers.get('content-disposition') | ||
filenames = re.findall('filename=(.+)', url_filename) | ||
if filenames: | ||
filename = filenames[0].replace('\"', '') | ||
filepath = pathlib.Path(destination_dir) / filename | ||
print(f"Downloading file to {filepath}") | ||
|
||
bytes_total = 0 | ||
with filepath.open("wb") as f: | ||
#shutil.copyfileobj(r_raw, f) | ||
with unreal.ScopedSlowTask(file_size, 'Downloading model') as slow_task: | ||
slow_task.make_dialog(True) | ||
for chunk in response.iter_content(1024): | ||
bytes_total += len(chunk) | ||
f.write(chunk) | ||
f.flush() | ||
downloader.update_game_thread(bytes_total) | ||
slow_task.enter_progress_frame(bytes_total, "Downloading") | ||
downloader.success_game_thread(file_size) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-9.87 KB
(98%)
StableDiffusionTools/Content/UI/Widgets/BP_StableDiffusionDependencyInstallerWidget.uasset
Binary file not shown.
Binary file added
BIN
+116 KB
StableDiffusionTools/Content/UI/Widgets/BP_StableDiffusionModelUtilities.uasset
Binary file not shown.
Binary file modified
BIN
+50.8 KB
(100%)
StableDiffusionTools/Content/UI/Widgets/BP_StableDiffusionViewportWidget.uasset
Binary file not shown.
Binary file modified
BIN
+183 Bytes
(100%)
StableDiffusionTools/Content/UI/Widgets/BP_ToggleButton.uasset
Binary file not shown.
Binary file added
BIN
+2.8 KB
StableDiffusionTools/Content/UI/Widgets/ViewportData/ECivitAiModelType.uasset
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
StableDiffusionTools/Source/StableDiffusionTools/Private/ModelAssetTools.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Copyright Epic Games, Inc. All Rights Reserved. | ||
|
||
#include "ModelAssetTools.h" | ||
#include "Modules/ModuleManager.h" | ||
#include "Misc/FileHelper.h" | ||
#include "IImageWrapperModule.h" | ||
#include "Interfaces/IHttpResponse.h" | ||
#include "HttpModule.h" | ||
#include "Async/Async.h" | ||
#include "IPythonScriptPlugin.h" | ||
|
||
#include UE_INLINE_GENERATED_CPP_BY_NAME(ModelAssetTools) | ||
|
||
|
||
//----------------------------------------------------------------------// | ||
// UAsyncTaskDownloadModel | ||
//----------------------------------------------------------------------// | ||
|
||
UAsyncTaskDownloadModel::UAsyncTaskDownloadModel(const FObjectInitializer& ObjectInitializer) | ||
: Super(ObjectInitializer) | ||
{ | ||
if (HasAnyFlags(RF_ClassDefaultObject) == false) | ||
{ | ||
AddToRoot(); | ||
} | ||
} | ||
|
||
UAsyncTaskDownloadModel* UAsyncTaskDownloadModel::DownloadModelCURL(FString URL, FString Path) | ||
{ | ||
UAsyncTaskDownloadModel* DownloadTask = NewObject<UAsyncTaskDownloadModel>(); | ||
DownloadTask->SavePath = Path; | ||
DownloadTask->Start(URL); | ||
|
||
return DownloadTask; | ||
} | ||
|
||
void UAsyncTaskDownloadModel::SuccessGameThread(int64 TotalBytes) | ||
{ | ||
AsyncTask(ENamedThreads::GameThread, [this, TotalBytes]() { | ||
OnSuccess.Broadcast(SavePath, TotalBytes); | ||
}); | ||
} | ||
|
||
void UAsyncTaskDownloadModel::UpdateGameThread(int64 TotalBytes) | ||
{ | ||
AsyncTask(ENamedThreads::GameThread, [this, TotalBytes]() { | ||
OnUpdate.Broadcast("", TotalBytes); | ||
}); | ||
} | ||
|
||
void UAsyncTaskDownloadModel::FailGameThread(int64 TotalBytes) | ||
{ | ||
AsyncTask(ENamedThreads::GameThread, [this, TotalBytes]() { | ||
OnFail.Broadcast("", TotalBytes); | ||
}); | ||
} | ||
|
||
void UAsyncTaskDownloadModel::Start(FString URL) | ||
{ | ||
#if !UE_SERVER | ||
// Create the Http request and add to pending request list | ||
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest(); | ||
|
||
HttpRequest->OnProcessRequestComplete().BindUObject(this, &UAsyncTaskDownloadModel::HandleHTTPRequest); | ||
HttpRequest->OnRequestProgress().BindUObject(this, &UAsyncTaskDownloadModel::HandleHTTPProgress); | ||
HttpRequest->SetURL(URL); | ||
HttpRequest->SetVerb(TEXT("GET")); | ||
HttpRequest->ProcessRequest(); | ||
#else | ||
// On the server we don't execute fail or success we just don't fire the request. | ||
RemoveFromRoot(); | ||
#endif | ||
} | ||
|
||
void UAsyncTaskDownloadModel::HandleHTTPProgress(FHttpRequestPtr Request, int32 TotalBytesWritten, int32 BytesWrittenSinceLastUpdate) | ||
{ | ||
// Don't send download updates too frequently otherwise we'll spam the blueprint thread | ||
if (BytesWrittenSinceLastUpdate - TotalBytesDownloaded > 1000000) { | ||
OnUpdate.Broadcast("", BytesWrittenSinceLastUpdate); | ||
TotalBytesDownloaded = BytesWrittenSinceLastUpdate; | ||
} | ||
} | ||
|
||
void UAsyncTaskDownloadModel::HandleHTTPRequest(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded) | ||
{ | ||
#if !UE_SERVER | ||
|
||
RemoveFromRoot(); | ||
|
||
if (bSucceeded && HttpResponse.IsValid() && HttpResponse->GetContentLength() > 0) | ||
{ | ||
TArray<uint8> ResponseData = HttpResponse->GetContent(); | ||
|
||
// Get filename from Content-Disposition header | ||
auto ContentDispHeader = HttpResponse->GetHeader(TEXT("Content-Disposition")); | ||
if (ContentDispHeader.IsEmpty()) | ||
{ | ||
UE_LOG(LogTemp, Error, TEXT("Failed to download file, no Content-Disposition header found")); | ||
OnFail.Broadcast("", ResponseData.Num()); | ||
return; | ||
} | ||
TArray<FString> ContentDisposition; | ||
ContentDispHeader.ParseIntoArray(ContentDisposition, TEXT(";"), true); | ||
auto Filename = ContentDisposition.FindByPredicate([](const FString& In) { | ||
return In.Contains(TEXT("filename=")); | ||
}); | ||
|
||
if (Filename) { | ||
FString SanitizedFilename = Filename->Replace(TEXT("filename="), TEXT("")).Replace(TEXT("\""), TEXT("")).TrimStartAndEnd(); | ||
// Save file content to disk | ||
|
||
FString FullSavePath = FPaths::Combine(*SavePath, *SanitizedFilename); | ||
|
||
if (FFileHelper::SaveArrayToFile(ResponseData, *FullSavePath)) | ||
{ | ||
UE_LOG(LogTemp, Warning, TEXT("File downloaded successfully to %s"), *FullSavePath); | ||
|
||
// Call the delegate | ||
OnSuccess.Broadcast(FullSavePath, ResponseData.Num()); | ||
} | ||
else | ||
{ | ||
UE_LOG(LogTemp, Error, TEXT("Failed to save file to %s"), *FullSavePath); | ||
} | ||
} | ||
else { | ||
UE_LOG(LogTemp, Error, TEXT("Failed to save file. No filename found in HTTP response.")); | ||
} | ||
} | ||
|
||
OnFail.Broadcast("", 0); | ||
|
||
#endif | ||
} | ||
|
||
|
||
//----------------------------------------------------------------------// | ||
|
||
UAsyncOperation::UAsyncOperation(const FObjectInitializer& ObjectInitializer) | ||
: Super(ObjectInitializer) | ||
{ | ||
if (HasAnyFlags(RF_ClassDefaultObject) == false) | ||
{ | ||
AddToRoot(); | ||
} | ||
} | ||
|
||
UAsyncOperation* UAsyncOperation::StartAsyncOperation() | ||
{ | ||
UAsyncOperation* Operation = NewObject<UAsyncOperation>(); | ||
|
||
AsyncTask(ENamedThreads::AnyThread, [Operation]() { | ||
Operation->OnStart.Broadcast(Operation); | ||
}); | ||
|
||
return Operation; | ||
} | ||
|
||
void UAsyncOperation::Complete() | ||
{ | ||
#if !UE_SERVER | ||
RemoveFromRoot(); | ||
AsyncTask(ENamedThreads::GameThread, [this]() { | ||
OnComplete.Broadcast(this); | ||
}); | ||
#endif | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.