Skip to content

Commit 3a44998

Browse files
committed
allow output folder path
1 parent a03fac1 commit 3a44998

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

StabilityMatrix.Core/Models/Packages/Cogstudio.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,31 @@ public override async Task InstallPackage(
6565

6666
progress?.Report(new ProgressReport(-1f, "Setting up Cogstudio files", isIndeterminate: true));
6767
var gradioCompositeDemo = new FilePath(installLocation, "inference/gradio_composite_demo");
68+
var cogstudioFile = new FilePath(gradioCompositeDemo, "cogstudio.py");
6869
gradioCompositeDemo.Directory?.Create();
6970
await DownloadService
70-
.DownloadToFileAsync(
71-
cogstudioUrl,
72-
new FilePath(gradioCompositeDemo, "cogstudio.py"),
73-
cancellationToken: cancellationToken
74-
)
71+
.DownloadToFileAsync(cogstudioUrl, cogstudioFile, cancellationToken: cancellationToken)
7572
.ConfigureAwait(false);
7673

74+
progress?.Report(
75+
new ProgressReport(
76+
-1f,
77+
"Patching cogstudio.py to allow writing to the output folder",
78+
isIndeterminate: true
79+
)
80+
);
81+
var outputDir = new FilePath(installLocation, "output");
82+
if (Compat.IsWindows)
83+
{
84+
outputDir = outputDir.ToString().Replace("\\", "\\\\");
85+
}
86+
var cogstudioContent = await cogstudioFile.ReadAllTextAsync(cancellationToken).ConfigureAwait(false);
87+
cogstudioContent = cogstudioContent.Replace(
88+
"demo.launch()",
89+
$"demo.launch(allowed_paths=['{outputDir}'])"
90+
);
91+
await cogstudioFile.WriteAllTextAsync(cogstudioContent, cancellationToken).ConfigureAwait(false);
92+
7793
progress?.Report(new ProgressReport(-1f, "Installing requirements", isIndeterminate: true));
7894
var requirements = new FilePath(installLocation, "requirements.txt");
7995
var pipArgs = new PipInstallArgs()

0 commit comments

Comments
 (0)