Skip to content

Commit

Permalink
Fixes for inpainting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Hiort af Ornäs committed Dec 5, 2024
1 parent 9a71779 commit 5488063
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/GetImgAiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ private function request(string $method, string $endpoint, ?array $params = null
{
$url = $this->baseUrl . $endpoint;

if (!empty($params) && 'GET' === $method) {
$url .= '?' . http_build_query($params);
}

$request = $this->requestFactory->createRequest($method, $url)
->withHeader('Authorization', 'Bearer ' . $this->apiKey)
->withHeader('Accept', 'application/json')
Expand Down
24 changes: 19 additions & 5 deletions src/Request/InpaintingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ public function __construct(
string $prompt,
string $image,
string $maskImage,
string $family = 'stable-diffusion-xl',
string $model = 'stable-diffusion-xl-v1-0',
?string $negativePrompt = null,
?string $prompt2 = null,
?string $negativePrompt2 = null,
float $strength = 0.8,
int $width = 1024,
int $height = 1024,
int $steps = 4,
int $steps = 30,
float $guidance = 7.5,
?int $seed = null,
string $outputFormat = 'jpeg',
Expand All @@ -46,7 +45,6 @@ public function __construct(
$this->setPrompt($prompt);
$this->setImage($image);
$this->setMaskImage($maskImage);
$this->setFamily($family);
$this->setModel($model);
$this->setNegativePrompt($negativePrompt);
$this->setPrompt2($prompt2);
Expand Down Expand Up @@ -107,20 +105,36 @@ public function setMaskImage(string $filePath): void

public function setModel(string $model): void
{
if (!in_array($model, ['stable-diffusion-xl-v1-0'], true)) {
$family = $this->getModelFamilies()[$model] ?? null;

$this->family = $family;

if (!$family) {
throw new InvalidArgumentException('Unsupported/untested model.');
}
$this->model = $model;
}

public function setFamily(string $family): void
{
if (!in_array($family, ['stable-diffusion-xl'], true)) {
$families = $this->getModelFamilies();

if (!in_array($family, $families, true)) {
throw new InvalidArgumentException('Unsupported/untested family.');
}
$this->family = $family;
}

private function getModelFamilies(): array
{
return [
'stable-diffusion-xl-v1-0' => 'stable-diffusion-xl',
'realistic-vision-v5-1-inpainting' => 'stable-diffusion',
'stable-diffusion-v1-5-inpainting' => 'stable-diffusion',
'realistic-vision-v1-3-inpainting' => 'stable-diffusion',
];
}

public function setStrength(float $strength): void
{
if ($strength < 0 || $strength > 1) {
Expand Down

0 comments on commit 5488063

Please sign in to comment.