Spaces:
Build error
Build error
File size: 3,945 Bytes
71f4839 e6b7912 0366183 e6b7912 0366183 e6b7912 0366183 71f4839 0366183 71f4839 0366183 71f4839 e6b7912 71f4839 0366183 71f4839 0366183 e6b7912 71f4839 e6b7912 0366183 7695918 b51e7a3 71f4839 0366183 71f4839 0366183 71f4839 0366183 71f4839 e6b7912 71f4839 e6b7912 0366183 71f4839 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
import requests; from requests.exceptions import Timeout
from io import BytesIO; from PIL import Image, ImageEnhance; import concurrent.futures, time
from modules.service_endpoints import *
from modules.input_configs import *
from modules.styles_anime import *
from modules.models_anime import *
from modules.service_configs import *
from modules.engine_upscale_alt import *
def gen_anime(prompt, model, style, size, quality, seed_type, seed_num):
prompt = stella_anime[style].format(prompt=prompt)
print(f"{receive()} -> {prompt}")
if seed_type == 'Randomized': seed_number = random.randint(0, max_seed)
else: seed_number = seed_num
data = {
'model_version': (None, '1'),
'prompt': (None, prompt),
'style_id': (None, ckpt_anime[str(model)]),
'negative_prompt': (None, 'hands, face, eyes, legs, nsfw, naked, nude, sexy'),
'aspect_ratio': (None, ratio[str(size)]),
'high_res_results': (None, '1'),
'cfg': (None, '9.5'),
'priority': (None, '1'),
'seed': (None, str(seed_number))
}
try:
response = requests.post(mode['generate'], headers=head, files=data, timeout=(60, 60))
if len(response.content) < 65 * 1024:
print(reject())
return None
print(done())
if quality == 'Enhanced':
print("better1 -> better output")
better1 = ImageEnhance.Contrast(
ImageEnhance.Color(
ImageEnhance.Brightness(
ImageEnhance.Sharpness(
Image.open(BytesIO(response.content))
).enhance(2.00)
).enhance(1.05)
).enhance(1.05)
).enhance(1.05)
return better1
if quality == 'Enhanced and Upscaled':
print("better2 -> better upscaled output")
better2 = ImageEnhance.Contrast(
ImageEnhance.Color(
ImageEnhance.Brightness(
ImageEnhance.Sharpness(
Image.open(BytesIO(response.content))
).enhance(2.00)
).enhance(1.05)
).enhance(1.05)
).enhance(1.05)
return upscale(better2)
if quality == 'Upscaled':
print("better3 -> upscaled output")
better3 = Image.open(BytesIO(response.content))
return upscale(better3)
else:
print("original -> raw output")
original = Image.open(BytesIO(response.content))
return original
except Timeout:
print(timeout())
return None
except Exception as e:
print(f"An error occurred: {e}")
ui.Warning(message=single_error)
return None
def queue_anime(a, b, c, d, e, f, g, h, progress=ui.Progress()):
if g == 'Randomized': quantities = 2
else: quantities = 1
result_list = [None] * quantities
percent = 0
if f == 'Fusion': a = translate(a)
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = []
for i in range(quantities):
future = executor.submit(lambda x: gen_anime(a, b, c, d, e, g, h), i)
futures.append(future)
multiplier = 0.95 / quantities
percent += multiplier
progress(percent, desc=f"Generating results")
time.sleep(0.25)
for i, future in enumerate(futures):
result = future.result()
result_list[i] = result
successful_results = [result for result in result_list if result is not None]
if g == 'Randomized': return successful_results, ui.Gallery(columns=1, rows=2)
else: return successful_results, ui.Gallery(columns=1, rows=1) |