-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
9 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/io/github/robothy/sdwebui/sdk/GetFaceRestorers.java
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,11 @@ | ||
package io.github.robothy.sdwebui.sdk; | ||
|
||
import io.github.robothy.sdwebui.sdk.models.results.FaceRestorer; | ||
|
||
import java.util.List; | ||
|
||
public interface GetFaceRestorers { | ||
|
||
List<FaceRestorer> getFaceRestorers(); | ||
|
||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/io/github/robothy/sdwebui/sdk/models/results/FaceRestorer.java
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,15 @@ | ||
package io.github.robothy.sdwebui.sdk.models.results; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class FaceRestorer { | ||
|
||
@JsonProperty("name") | ||
private String name; | ||
|
||
@JsonProperty("cmd_dir") | ||
private String cmdDir; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/github/robothy/sdwebui/sdk/services/DefaultGetFaceRestorersService.java
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,23 @@ | ||
package io.github.robothy.sdwebui.sdk.services; | ||
|
||
import io.github.robothy.sdwebui.sdk.GetFaceRestorers; | ||
import io.github.robothy.sdwebui.sdk.SdWebuiBeanContainer; | ||
import io.github.robothy.sdwebui.sdk.models.results.FaceRestorer; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class DefaultGetFaceRestorersService implements GetFaceRestorers { | ||
|
||
private final SdWebuiBeanContainer container; | ||
|
||
public DefaultGetFaceRestorersService(SdWebuiBeanContainer container) { | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public List<FaceRestorer> getFaceRestorers() { | ||
return Arrays.asList(container.getBean(CommonGetService.class).getData("/sdapi/v1/face-restorers", FaceRestorer[].class)); | ||
} | ||
|
||
} |
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
40 changes: 40 additions & 0 deletions
40
src/test/java/io/github/robothy/sdwebui/sdk/GetFaceRestorersTest.java
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,40 @@ | ||
package io.github.robothy.sdwebui.sdk; | ||
|
||
import io.github.robothy.sdwebui.sdk.models.results.FaceRestorer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockserver.client.MockServerClient; | ||
import org.mockserver.junit.jupiter.MockServerExtension; | ||
import org.mockserver.model.HttpRequest; | ||
import org.mockserver.model.HttpResponse; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@ExtendWith(MockServerExtension.class) | ||
class GetFaceRestorersTest { | ||
|
||
@Test | ||
void getFaceRestorers(MockServerClient client) { | ||
client.when(new HttpRequest().withMethod("GET").withPath("/sdapi/v1/face-restorers")) | ||
.respond(new HttpResponse().withStatusCode(200).withBody("[\n" + | ||
" {\n" + | ||
" \"name\": \"CodeFormer\",\n" + | ||
" \"cmd_dir\": \"C:\\\\Users\\\\admin\\\\PythonProjects\\\\stable-diffusion-webui\\\\models\\\\Codeformer\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"name\": \"GFPGAN\",\n" + | ||
" \"cmd_dir\": null\n" + | ||
" }\n" + | ||
"]")); | ||
|
||
List<FaceRestorer> faceRestorers = SdWebui.create("http://localhost:" + client.getPort()) | ||
.getFaceRestorers(); | ||
assertEquals(2, faceRestorers.size()); | ||
assertEquals("CodeFormer", faceRestorers.get(0).getName()); | ||
assertEquals("C:\\Users\\admin\\PythonProjects\\stable-diffusion-webui\\models\\Codeformer", faceRestorers.get(0).getCmdDir()); | ||
assertEquals("GFPGAN", faceRestorers.get(1).getName()); | ||
assertNull(faceRestorers.get(1).getCmdDir()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/io/github/robothy/sdwebui/sdk/models/results/FaceRestorerTest.java
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,31 @@ | ||
package io.github.robothy.sdwebui.sdk.models.results; | ||
|
||
import io.github.robothy.sdwebui.sdk.utils.JsonUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class FaceRestorerTest { | ||
|
||
@Test | ||
void testSerialization() { | ||
String faceRestorersJson = "[\n" + | ||
" {\n" + | ||
" \"name\": \"CodeFormer\",\n" + | ||
" \"cmd_dir\": \"C:\\\\Users\\\\admin\\\\PythonProjects\\\\stable-diffusion-webui\\\\models\\\\Codeformer\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"name\": \"GFPGAN\",\n" + | ||
" \"cmd_dir\": null\n" + | ||
" }\n" + | ||
"]"; | ||
|
||
FaceRestorer[] faceRestorers = JsonUtils.fromJson(faceRestorersJson, FaceRestorer[].class); | ||
assertEquals(2, faceRestorers.length); | ||
assertEquals("CodeFormer", faceRestorers[0].getName()); | ||
assertEquals("C:\\Users\\admin\\PythonProjects\\stable-diffusion-webui\\models\\Codeformer", faceRestorers[0].getCmdDir()); | ||
assertEquals("GFPGAN", faceRestorers[1].getName()); | ||
assertNull(faceRestorers[1].getCmdDir()); | ||
} | ||
|
||
} |