Skip to content

Commit

Permalink
kojii endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
genekogan committed Mar 7, 2024
1 parent c5cc80a commit b77f8d7
Show file tree
Hide file tree
Showing 13 changed files with 784 additions and 68 deletions.
29 changes: 2 additions & 27 deletions app/animations/little_martians.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def little_martian_poster(request: LittleMartianRequest):
"lora_scale": lora_scale,
"init_image": f'https://edenartlab-prod-data.s3.us-east-1.amazonaws.com/{init_image}',
"init_image_strength": init_image_strength,
"width": w,
"height": h,
"width": width,
"height": height,
"adopt_aspect_from_init_img": False,
"n_samples": 1,
}
Expand All @@ -79,35 +79,10 @@ def little_martian_poster(request: LittleMartianRequest):
image = utils.download_image(image_url)
composite_image, thumbnail_image = poster(image, caption)

print("-========-")
# results = utils.process_in_parallel(
# comic_book['panels'],
# run_panel,
# max_workers=4
# )

# image_urls = [image_url for image_url, thumbnail in results]
# images = [utils.download_image(url) for url in image_urls]
# captions = [panel['caption'] for panel in comic_book['panels']]

# composite_image, thumbnail_image = comic_strip(images, captions)

img_bytes = utils.PIL_to_bytes(composite_image, ext="JPEG")
thumbnail_bytes = utils.PIL_to_bytes(thumbnail_image, ext="WEBP")

output_url = s3.upload(img_bytes, "jpg")
thumbnail_url = s3.upload(thumbnail_bytes, "webp")

# download output_url
# martian, setting, genre, pr = request.martian.value, request.setting.value, request.genre.value, request.prompt

# filename = f'{martian}_{setting}_{genre}_{pr}.jpg'

# with open(filename, "wb") as f:
# f.write(requests.get(output_url).content)

# # save config as json file
# with open(f"{filename}.json", "w") as f:
# f.write(str(config))

return output_url, thumbnail_url
1 change: 0 additions & 1 deletion app/animations/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ..models import StoryRequest
from .animation import screenplay_clip

MAX_PIXELS = 1024 * 1024
MAX_WORKERS = 3


Expand Down
5 changes: 5 additions & 0 deletions app/creation_interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .kojii_makeitrad import KojiiMakeitradRequest, kojii_makeitrad
from .kojii_chebel import KojiiChebelRequest, kojii_chebel
from .kojii_untitledxyz import KojiiUntitledxyzRequest, kojii_untitledxyz
from .kojii_violetforest import KojiiVioletforestRequest, kojii_violetforest
from .kojii_huemin import KojiiHueminRequest, kojii_huemin
310 changes: 310 additions & 0 deletions app/creation_interfaces/kojii_chebel.py

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions app/creation_interfaces/kojii_huemin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import random
from enum import Enum
from typing import Optional, List
from pydantic import BaseModel, Field

from ..plugins import replicate


class KojiiHueminRequest(BaseModel):
"""
A request for Huemin endpoint
"""
prompt: Optional[str] = Field(default=None, description="Prompt")


def kojii_huemin(request: KojiiHueminRequest, callback=None):
config = {
"mode": "huemin",
"prompt": request.prompt
}

image_url, thumbnail_url = replicate.sdxl(config)

return image_url, thumbnail_url
128 changes: 128 additions & 0 deletions app/creation_interfaces/kojii_makeitrad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import random
from enum import Enum
from typing import Optional, List
from pydantic import BaseModel, Field

from ..plugins import replicate


class Setting(Enum):
inside = "inside"
outside = "outside"

class Location(Enum):
jungle = "jungle"
cliff_front = "cliff front"
desert = "desert"
redwood_forest = "redwood forest"
city_suburbia = "city suburbia"
montana_mountains = "montana mountains"
green_hills = "green hills"

class Time(Enum):
noon = "noon"
dawn = "dawn"
red_sunset = "red sunset"
night = "night"

class Color(Enum):
default = "default"
orange = "orange"
yellow_green = "yellow/green"
light_blue = "light blue"
light_pink = "light pink"

class AspectRatio(Enum):
portrait = "portrait"
landscape = "landscape"
square = "square"

class KojiiMakeitradRequest(BaseModel):
"""
A request for Makeitrad endpoint
"""
setting: Setting
location: Location
time: Time
color: Color
clouds: bool
pool: bool
aspect_ratio: AspectRatio


settings = {
"inside": "interior",
"outside": "exterior"
}

locations = {
"jungle": "surrounded by overgrown plants, in the lush jungle, large leaves",
"cliff front": "cliff ocean front overlooking water, tropical plants",
"desert": "desert (large rock formations:1.5), cactus, succulents and red sands",
"redwood forest": "in the lush redwood forest with a running river",
"city suburbia": "urban city suburbia, (house plants) and (outdoor topiaries:1.5)",
"montana mountains": "dramatic winter snow capped rustic Montana mountains, trees",
"green hills": "rolling green grass hills and colorful wild flowers"
}

times = {
"noon": "high noon",
"dawn": "dawn light with hazy fog",
"red sunset": "night red sunset",
"night": "dark black night with large moon and stars"
}

colors = {
"default": "",
"orange": "orange accents",
"yellow/green": "yellow and green accents",
"light blue": "light blue accents",
"light pink": "light pink accents"
}

resolutions = {
"portrait": (768, 1344),
"landscape": (1344, 768),
"square": (1024, 1024)
}

def kojii_makeitrad(request: KojiiMakeitradRequest, callback=None):
setting = settings[request.setting.value]
location = locations[request.location.value]
time = times[request.time.value]
color = colors[request.color.value]

clouds = "clouds, " if request.clouds else ""
pool = "(pool:1.5)," if request.pool else ""

prompt = f"In the style of makeitrad, highly detailed, graphic illustration, almost photorealistic image of an ({setting}:1.5) extra wide angle Landscape mid-century architecture, indoor-outdoor living atrium, {location}, at {time}, {color}, {clouds}{pool} 8k resolution, in the style of midcentury architectural greats. Post and beam, modern glossy, Kodak Portra 100. embedding:makeitrad_embeddings embedding:indoor-outdoor_embeddings"

neg_pool = "pool, " if not request.pool else ""
neg_clouds = "clouds, " if not request.clouds else ""

negative_prompt = f"{neg_pool}{neg_clouds} watermark, text, ugly, tiling, out of frame, blurry, blurred, grainy, signature, cut off, draft"

width, height = resolutions[request.aspect_ratio.value]

config = {
"mode": "makeitrad",
"text_input": prompt,
"width": width,
"height": height,
"n_samples": 1,
"negative_prompt": negative_prompt,
"guidance_scale": 7,
"seed": random.randint(0, 1000000),
}

output = replicate.run_task(
config,
model_name="abraham-ai/eden-comfyui"
)

output = list(output)
image_url = output[0]["files"][0]
thumbnail_url = output[0]["thumbnails"][0]

return image_url, thumbnail_url

21 changes: 21 additions & 0 deletions app/creation_interfaces/kojii_untitledxyz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import random
from enum import Enum
from typing import Optional, List
from pydantic import BaseModel, Field

from ..plugins import replicate


class Type(Enum):
column = "column"
context = "context"

class KojiiUntitledxyzRequest(BaseModel):
"""
A request for Untitledxyz endpoint
"""
type: Type = Field(default=Type.column, description="Column or Context")
human_machine_nature: float = Field(default=0.5, description="Human (0) vs machine (0.5) vs nature (1)", ge=0.0, le=1.0)

def kojii_untitledxyz(request: KojiiUntitledxyzRequest, callback=None):
return {"hello": "world"}
45 changes: 45 additions & 0 deletions app/creation_interfaces/kojii_violetforest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import random
from enum import Enum
from typing import Optional, List
from pydantic import BaseModel, Field

from ..plugins import replicate


class Style(Enum):
Kawaii = "Kawaii"
Stars = "Stars"
Lace = "Lace"
Flowers = "Flowers"

class KojiiVioletforestRequest(BaseModel):
"""
A request for VioletForest endpoint
"""
cybertwee_cyberpunk: float = Field(default=0.5, description="Cybertwee vs Cyberpunk", ge=0.0, le=1.0)
style: Style = Field(default=Style.Kawaii, description="Style")


def kojii_violetforest(request: KojiiVioletforestRequest, callback=None):
if request.style == Style.Kawaii:
modifiers = "kawaii, kawaii, kawaii, kawaii"
elif request.style == Style.Stars:
modifiers = "stars, stars, stars, stars"
elif request.style == Style.Lace:
modifiers = "lace, lace, lace, lace"
elif request.style == Style.Flowers:
modifiers = "flowers, flowers, flowers, flowers"

prompt1 = f"a stunning image of a cute cybertwee girl, {modifiers}"
prompt2 = f"a stunning image of an Aston Martin sportscar, {modifiers}"

config = {
"mode": "create",
"text_input": prompt1,
"lora": "https://edenartlab-prod-data.s3.us-east-1.amazonaws.com/e3b036c0a9949de0a5433cb6c7e54b540c47535ce7ae252948177304542ca4da.tar",
"lora_scale": 0.7,
}

image_url, thumbnail_url = replicate.sdxl(config)

return image_url, thumbnail_url
Loading

0 comments on commit b77f8d7

Please sign in to comment.