Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kojii endpoints #33

Merged
merged 7 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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

from ..plugins import replicate



class Climate(Enum):
arid = "arid"
temperate = "temperate"
tropical = "tropical"
alpine = "alpine"
cold = "cold"
warm = "warm"
humid = "humid"
dry = "dry"
mediterranean = "mediterranean"
oceanic = "oceanic"
continental = "continental"
polar = "polar"
subtropical = "subtropical"
desert = "desert"
savanna = "savanna"
rainforest = "rainforest"
tundra = "tundra"
monsoon = "monsoon"
steppe = "steppe"


class Landform(Enum):
mountains = "mountains"
valleys = "valleys"
plateaus = "plateaus"
hills = "hills"
plains = "plains"
dunes = "dunes"
canyons = "canyons"
cliffs = "cliffs"
caves = "caves"
volcanoes = "volcanoes"
rivers = "rivers"
lakes = "lakes"
glaciers = "glaciers"
fjords = "fjords"
deltas = "deltas"
estuaries = "estuaries"
wetlands = "wetlands"
deserts = "deserts"
craters = "craters"
atolls = "atolls"
peninsula = "peninsula"
islands = "islands"
basins = "basins"
gorges = "gorges"
waterfalls = "waterfalls"
rift_valleys = "rift valleys"

class BodyOfWater(Enum):
oceans = "oceans"
seas = "seas"
rivers = "rivers"
lakes = "lakes"
ponds = "ponds"
streams = "streams"
creeks = "creeks"
estuaries = "estuaries"
fjords = "fjords"
bays = "bays"
gulfs = "gulfs"
lagoons = "lagoons"
marshes = "marshes"
swamps = "swamps"
reservoirs = "reservoirs"
waterfalls = "waterfalls"
glacial_lakes = "glacial lakes"
wetlands = "wetlands"
springs = "springs"
brooks = "brooks"

class Structure(Enum):
bridges = "bridges"
tunnels = "tunnels"
dams = "dams"
skyscrapers = "skyscrapers"
castles = "castles"
temples = "temples"
churches = "churches"
mosques = "mosques"
fortresses = "fortresses"
monuments = "monuments"
statues = "statues"
towers = "towers"
silos = "silos"
industrial_factories = "industrial factories"
piers = "piers"
harbors = "harbors"

class Season(Enum):
spring = "spring"
summer = "summer"
autumn = "autumn"
winter = "winter"
rainy = "rainy"
sunny = "sunny"
cloudy = "cloudy"
stormy_clouds = "stormy clouds"
foggy_mist = "foggy mist"
snowy = "snowy"
windy = "windy"
humid = "humid"
dry = "dry"
hot = "hot"
cold = "cold"
mild = "mild"
freezing = "freezing"
thunderstorms = "thunderstorms"
hail = "hail"
sleet = "sleet"
blizzard = "blizzard"
heatwave = "heatwave"
drought = "drought"

class TimeOfDay(Enum):
dawn = "dawn"
morning = "morning"
noon = "noon"
afternoon = "afternoon"
dusk = "dusk"
evening = "evening"
sunset = "sunset"

class Color(Enum):
monochromatic = "monochromatic"
analogous = "analogous"
complementary = "complementary"
split_complementary = "split-complementary"
triadic = "triadic"
tetradic = "tetradic"
square = "square"
neutral = "neutral"
pastel = "pastel"
warm = "warm"
cool = "cool"
vibrant = "vibrant"
muted = "muted"
earth_tones = "earth tones"
jewel_tones = "jewel tones"
metallic = "metallic"


class KojiiHueminRequest(BaseModel):
"""
A request for Huemin endpoint
"""
climate: Climate
landform: Landform
body_of_water: BodyOfWater
# structure: Structure
# season: Season
# time_of_day: TimeOfDay
# color: Color


def generate_prompt(selected_climate, selected_landform, selected_body_of_water):
base_prompt = "isometric generative landscape orthographic abstract aj casson perlin noise 3d shaders areal embroidery minimalism claude monet oil painting pastel"

selected_structure = random.choice(list(Structure)).value
selected_season = random.choice(list(Season)).value
selected_time_of_day = random.choice(list(TimeOfDay)).value
selected_colors = random.choice(list(Color)).value

selected_keywords = [selected_climate.value, selected_landform.value, selected_body_of_water.value, selected_structure, selected_season, selected_time_of_day, selected_colors]
landscape_keywords = " ".join(selected_keywords)

prompt = base_prompt + " (((" + landscape_keywords + ")))"
return prompt


def kojii_huemin(request: KojiiHueminRequest, callback=None):
prompt = generate_prompt(request.climate, request.landform, request.body_of_water)

config = {
"mode": "kojii/huemin",
"text_input": 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

Loading
Loading