-
Notifications
You must be signed in to change notification settings - Fork 0
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
14 changed files
with
111 additions
and
40 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .client import MAX_RETRIES, USER_AGENT, INITIAL_BACKOFF, SUBSEQUENT_BACKOFF | ||
from .models import SDXL |
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 @@ | ||
SDXL = "stability-ai/sdxl" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
|
||
from black import Optional | ||
|
||
from deepinfra import BaseModel | ||
from deepinfra.constants import SDXL | ||
from deepinfra.types.sdxl.request import SdxlRequest | ||
from deepinfra.types.sdxl.response import SdxlResponse | ||
|
||
|
||
class Sdxl(BaseModel): | ||
""" | ||
Class for the SDXL model. | ||
@docs Check the model at https://deepinfra.com/stability-ai/sdxl/api | ||
""" | ||
|
||
def __init__(self, api_token: Optional[str] = None): | ||
super().__init__(SDXL, api_token) | ||
|
||
def generate(self, body: dict) -> SdxlResponse: | ||
""" | ||
Generates an image. | ||
:param input: | ||
:return: | ||
""" | ||
response = self.client.post(json.dumps(body)) | ||
return response.json() |
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
Empty file.
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 @@ | ||
from typing import Optional | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class SdxlRequest: | ||
prompt: str | ||
negative_prompt: Optional[str] = None | ||
image: Optional[str] = None | ||
mask: Optional[str] = None | ||
width: Optional[int] = None | ||
height: Optional[int] = None | ||
num_outputs: Optional[int] = None | ||
scheduler: Optional[str] = None | ||
num_inference_steps: Optional[int] = None | ||
guidance_scale: Optional[float] = None | ||
prompt_strength: Optional[float] = None | ||
seed: Optional[int] = None | ||
refine: Optional[str] = None | ||
high_noise_frac: Optional[float] = None | ||
refine_steps: Optional[int] = None | ||
apply_watermark: Optional[bool] = True |
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,16 @@ | ||
from typing import List | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class SdxlResponseItem: | ||
format: str | ||
type: str | ||
|
||
|
||
@dataclass | ||
class SdxlResponse: | ||
items: List[SdxlResponseItem] | ||
title: str | ||
type: str |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
setuptools | ||
setuptools-scm | ||
requests | ||
dataclasses | ||
requests-toolbelt | ||
requests-toolbelt | ||
pydantic |
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,28 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from deepinfra import TextToImage | ||
from deepinfra.constants import SDXL | ||
from deepinfra.models.base.sdxl import Sdxl | ||
|
||
model_name = SDXL | ||
api_key = "API KEY" | ||
|
||
|
||
class TestSdxl(unittest.TestCase): | ||
@patch("requests.post") | ||
def test_generate(self, mock_post): | ||
mock_post.return_value.status_code = 200 | ||
mock_post.return_value.json.return_value = {"image": "image data"} | ||
|
||
text_to_image = Sdxl(api_key) | ||
body = {"input": {"prompt": "Hello, World!"}} | ||
response = text_to_image.generate(body) | ||
|
||
called_args, called_kwargs = mock_post.call_args | ||
url = called_args[0] | ||
header = called_kwargs["headers"] | ||
self.assertEqual(url, f"https://api.deepinfra.com/v1/inference/{model_name}") | ||
|
||
self.assertEqual(response["image"], "image data") | ||
self.assertEqual(header["Authorization"], f"Bearer {api_key}") |