Spaces:
Build error
Build error
added/updated app files
Browse files- README.md +1 -1
- app.py β app_anime.py +13 -9
- modules/engine_anime.py +27 -33
- modules/engine_upscale_alt.py +3 -11
- modules/input_configs.py +7 -29
- modules/models_anime.py +3 -3
- modules/service_configs.py +241 -38
- modules/service_endpoints.py +2 -1
README.md
CHANGED
@@ -5,7 +5,7 @@ colorFrom: blue
|
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.20.1
|
8 |
-
app_file:
|
9 |
pinned: false
|
10 |
license: agpl-3.0
|
11 |
---
|
|
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.20.1
|
8 |
+
app_file: app_anime.py
|
9 |
pinned: false
|
10 |
license: agpl-3.0
|
11 |
---
|
app.py β app_anime.py
RENAMED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
feature = 'Text-to-Image - Anime'
|
3 |
'''
|
4 |
_____________________________________________________________________
|
@@ -11,23 +11,27 @@ _____________________________________________________________________
|
|
11 |
_____________________________________________________________________
|
12 |
|
13 |
'''
|
14 |
-
with ui.Blocks(css=css, title=title(feature), theme=theme, analytics_enabled=False) as stella:
|
15 |
with ui.Group():
|
16 |
-
result_anime = ui.Gallery(label=title(feature), object_fit="contain", height="
|
17 |
-
prompt_anime = ui.Textbox(
|
18 |
with ui.Row():
|
19 |
clear_anime = ui.ClearButton(value="Reset", components=[result_anime, prompt_anime])
|
20 |
submit_anime= ui.Button("Submit", variant="primary")
|
21 |
|
22 |
-
with ui.Accordion('
|
23 |
style_anime = ui.Dropdown(label=sstyle, choices=list(stella_anime.keys()), value='None', filterable=False)
|
24 |
model_anime = ui.Dropdown(label=smodel, choices=list(ckpt_anime.keys()), value='Rev Animated', filterable=False)
|
25 |
ratio_anime = ui.Dropdown(label=sratio, choices=list(ratio.keys()), value='Square (1:1)', filterable=False)
|
26 |
quality_anime = ui.Dropdown(label=squality, choices=quality, value='Enhanced', filterable=False)
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
-
process_anime = submit_anime.click(fn=quads_anime, inputs=[prompt_anime, model_anime, style_anime, ratio_anime, quality_anime,
|
30 |
-
prompt_anime.submit(fn=quads_anime, inputs=[prompt_anime, model_anime, style_anime, ratio_anime, quality_anime,
|
|
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
-
stella.queue(default_concurrency_limit=100
|
|
|
1 |
+
from modules.engine_anime import *
|
2 |
feature = 'Text-to-Image - Anime'
|
3 |
'''
|
4 |
_____________________________________________________________________
|
|
|
11 |
_____________________________________________________________________
|
12 |
|
13 |
'''
|
14 |
+
with ui.Blocks(css=css, title=title(feature), theme=theme, analytics_enabled=False, head=jsx) as stella:
|
15 |
with ui.Group():
|
16 |
+
result_anime = ui.Gallery(label=title(feature), object_fit="contain", height="98vh", show_share_button=False)
|
17 |
+
prompt_anime = ui.Textbox(label=sprompt, placeholder=spholder)
|
18 |
with ui.Row():
|
19 |
clear_anime = ui.ClearButton(value="Reset", components=[result_anime, prompt_anime])
|
20 |
submit_anime= ui.Button("Submit", variant="primary")
|
21 |
|
22 |
+
with ui.Accordion('More options'):
|
23 |
style_anime = ui.Dropdown(label=sstyle, choices=list(stella_anime.keys()), value='None', filterable=False)
|
24 |
model_anime = ui.Dropdown(label=smodel, choices=list(ckpt_anime.keys()), value='Rev Animated', filterable=False)
|
25 |
ratio_anime = ui.Dropdown(label=sratio, choices=list(ratio.keys()), value='Square (1:1)', filterable=False)
|
26 |
quality_anime = ui.Dropdown(label=squality, choices=quality, value='Enhanced', filterable=False)
|
27 |
+
smart_anime = ui.Dropdown(label=ssmart, choices=['Disabled', 'Fusion'], value='Disabled', filterable=False)
|
28 |
+
with ui.Row():
|
29 |
+
seedtype_anime = ui.Dropdown(label='Seed type:', choices=['Randomized', 'Fixed'], value='Randomized', filterable=False)
|
30 |
+
seedno_anime = ui.Number(label='Seed value:', value=0, minimum=0, maximum=max_seed, visible=False)
|
31 |
|
32 |
+
process_anime = submit_anime.click(fn=quads_anime, inputs=[prompt_anime, model_anime, style_anime, ratio_anime, quality_anime, smart_anime, seedtype_anime, seedno_anime], outputs=[result_anime, result_anime])
|
33 |
+
prompt_anime.submit(fn=quads_anime, inputs=[prompt_anime, model_anime, style_anime, ratio_anime, quality_anime, smart_anime, seedtype_anime, seedno_anime], outputs=[result_anime, result_anime])
|
34 |
+
seedtype_anime.select(fn=seeds, inputs=seedtype_anime, outputs=seedno_anime)
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
+
stella.queue(default_concurrency_limit=100).launch(inbrowser=True, favicon_path="favicon.ico")
|
modules/engine_anime.py
CHANGED
@@ -1,10 +1,6 @@
|
|
1 |
-
import
|
2 |
from io import BytesIO; from PIL import Image, ImageEnhance; import concurrent.futures, time
|
3 |
|
4 |
-
###################################################################################################################
|
5 |
-
# Import from modules
|
6 |
-
###################################################################################################################
|
7 |
-
|
8 |
from modules.service_endpoints import *
|
9 |
from modules.input_configs import *
|
10 |
from modules.styles_anime import *
|
@@ -12,27 +8,27 @@ from modules.models_anime import *
|
|
12 |
from modules.service_configs import *
|
13 |
from modules.engine_upscale_alt import *
|
14 |
|
15 |
-
|
16 |
-
# Image generation process
|
17 |
-
###################################################################################################################
|
18 |
-
|
19 |
-
def gen_anime(prompt, model, style, size, quality):
|
20 |
prompt = stella_anime[style].format(prompt=prompt)
|
21 |
print(f"{receive()} -> {prompt}")
|
22 |
|
|
|
|
|
|
|
23 |
data = {
|
24 |
'model_version': (None, '1'),
|
25 |
'prompt': (None, prompt),
|
26 |
'style_id': (None, ckpt_anime[str(model)]),
|
27 |
-
'negative_prompt': (None, 'hands, face, eyes, legs,
|
28 |
'aspect_ratio': (None, ratio[str(size)]),
|
29 |
'high_res_results': (None, '1'),
|
30 |
'cfg': (None, '9.5'),
|
31 |
'priority': (None, '1'),
|
|
|
32 |
}
|
33 |
|
34 |
try:
|
35 |
-
response = requests.post(mode['generate'], headers=head, files=data, timeout=
|
36 |
|
37 |
if len(response.content) < 65 * 1024:
|
38 |
print(reject())
|
@@ -65,7 +61,12 @@ def gen_anime(prompt, model, style, size, quality):
|
|
65 |
).enhance(1.05)
|
66 |
).enhance(1.05)
|
67 |
return upscale(better2)
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
else:
|
70 |
print("original -> raw output")
|
71 |
original = Image.open(BytesIO(response.content))
|
@@ -80,24 +81,24 @@ def gen_anime(prompt, model, style, size, quality):
|
|
80 |
ui.Warning(message=single_error)
|
81 |
return None
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
def quads_anime(a, b, c, d, e, f, progress=ui.Progress()):
|
88 |
-
quantities = int(f)
|
89 |
result_list = [None] * quantities
|
90 |
percent = 0
|
91 |
-
|
|
|
|
|
92 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
93 |
futures = []
|
94 |
|
95 |
for i in range(quantities):
|
96 |
-
future = executor.submit(lambda x: gen_anime(a, b, c, d, e), i)
|
97 |
futures.append(future)
|
98 |
-
multiplier = 0.
|
99 |
percent += multiplier
|
100 |
-
progress(percent, desc=f"
|
101 |
time.sleep(0.25)
|
102 |
|
103 |
for i, future in enumerate(futures):
|
@@ -105,13 +106,6 @@ def quads_anime(a, b, c, d, e, f, progress=ui.Progress()):
|
|
105 |
result_list[i] = result
|
106 |
|
107 |
successful_results = [result for result in result_list if result is not None]
|
108 |
-
|
109 |
-
if
|
110 |
-
|
111 |
-
ui.Warning(message=single_error)
|
112 |
-
else:
|
113 |
-
ui.Warning(message=quads_error)
|
114 |
-
else:
|
115 |
-
pass
|
116 |
-
|
117 |
-
return successful_results
|
|
|
1 |
+
import requests; from requests.exceptions import Timeout
|
2 |
from io import BytesIO; from PIL import Image, ImageEnhance; import concurrent.futures, time
|
3 |
|
|
|
|
|
|
|
|
|
4 |
from modules.service_endpoints import *
|
5 |
from modules.input_configs import *
|
6 |
from modules.styles_anime import *
|
|
|
8 |
from modules.service_configs import *
|
9 |
from modules.engine_upscale_alt import *
|
10 |
|
11 |
+
def gen_anime(prompt, model, style, size, quality, seed_type, seed_num):
|
|
|
|
|
|
|
|
|
12 |
prompt = stella_anime[style].format(prompt=prompt)
|
13 |
print(f"{receive()} -> {prompt}")
|
14 |
|
15 |
+
if seed_type == 'Randomized': seed_number = random.randint(0, max_seed)
|
16 |
+
else: seed_number = seed_num
|
17 |
+
|
18 |
data = {
|
19 |
'model_version': (None, '1'),
|
20 |
'prompt': (None, prompt),
|
21 |
'style_id': (None, ckpt_anime[str(model)]),
|
22 |
+
'negative_prompt': (None, 'hands, face, eyes, legs, nsfw, naked, nude, sexy'),
|
23 |
'aspect_ratio': (None, ratio[str(size)]),
|
24 |
'high_res_results': (None, '1'),
|
25 |
'cfg': (None, '9.5'),
|
26 |
'priority': (None, '1'),
|
27 |
+
'seed': (None, str(seed_number))
|
28 |
}
|
29 |
|
30 |
try:
|
31 |
+
response = requests.post(mode['generate'], headers=head, files=data, timeout=(60, 60))
|
32 |
|
33 |
if len(response.content) < 65 * 1024:
|
34 |
print(reject())
|
|
|
61 |
).enhance(1.05)
|
62 |
).enhance(1.05)
|
63 |
return upscale(better2)
|
64 |
+
|
65 |
+
if quality == 'Upscaled':
|
66 |
+
print("better3 -> upscaled output")
|
67 |
+
better3 = Image.open(BytesIO(response.content))
|
68 |
+
return upscale(better3)
|
69 |
+
|
70 |
else:
|
71 |
print("original -> raw output")
|
72 |
original = Image.open(BytesIO(response.content))
|
|
|
81 |
ui.Warning(message=single_error)
|
82 |
return None
|
83 |
|
84 |
+
def quads_anime(a, b, c, d, e, f, g, h, progress=ui.Progress()):
|
85 |
+
if g == 'Randomized': quantities = 2
|
86 |
+
else: quantities = 1
|
87 |
+
|
|
|
|
|
88 |
result_list = [None] * quantities
|
89 |
percent = 0
|
90 |
+
|
91 |
+
if f == 'Fusion': a = translate(a)
|
92 |
+
|
93 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
94 |
futures = []
|
95 |
|
96 |
for i in range(quantities):
|
97 |
+
future = executor.submit(lambda x: gen_anime(a, b, c, d, e, g, h), i)
|
98 |
futures.append(future)
|
99 |
+
multiplier = 0.95 / quantities
|
100 |
percent += multiplier
|
101 |
+
progress(percent, desc=f"Generating results")
|
102 |
time.sleep(0.25)
|
103 |
|
104 |
for i, future in enumerate(futures):
|
|
|
106 |
result_list[i] = result
|
107 |
|
108 |
successful_results = [result for result in result_list if result is not None]
|
109 |
+
|
110 |
+
if g == 'Randomized': return successful_results, ui.Gallery(columns=1, rows=2)
|
111 |
+
else: return successful_results, ui.Gallery(columns=1, rows=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/engine_upscale_alt.py
CHANGED
@@ -1,17 +1,9 @@
|
|
1 |
-
import
|
2 |
from io import BytesIO; from PIL import Image
|
3 |
|
4 |
-
###################################################################################################################
|
5 |
-
# Import from modules
|
6 |
-
###################################################################################################################
|
7 |
-
|
8 |
from modules.service_endpoints import *
|
9 |
from modules.service_configs import *
|
10 |
|
11 |
-
###################################################################################################################
|
12 |
-
# Image upscale process
|
13 |
-
###################################################################################################################
|
14 |
-
|
15 |
def upscale(upscale_input, progress=ui.Progress()):
|
16 |
image_bytes = BytesIO()
|
17 |
upscale_input.save(image_bytes, format='JPEG')
|
@@ -20,8 +12,8 @@ def upscale(upscale_input, progress=ui.Progress()):
|
|
20 |
payload = {'model_version': (None, '1')}; data = [('image',('upscale_input.jpg', image_bytes.getvalue(), 'image/jpeg'))]
|
21 |
|
22 |
try:
|
23 |
-
progress(0.
|
24 |
-
response = requests.post(mode['upscale'], headers=head, data=payload, files=data, timeout=
|
25 |
|
26 |
if len(response.content) < 65 * 1024:
|
27 |
print(reject())
|
|
|
1 |
+
import requests; from requests.exceptions import Timeout
|
2 |
from io import BytesIO; from PIL import Image
|
3 |
|
|
|
|
|
|
|
|
|
4 |
from modules.service_endpoints import *
|
5 |
from modules.service_configs import *
|
6 |
|
|
|
|
|
|
|
|
|
7 |
def upscale(upscale_input, progress=ui.Progress()):
|
8 |
image_bytes = BytesIO()
|
9 |
upscale_input.save(image_bytes, format='JPEG')
|
|
|
12 |
payload = {'model_version': (None, '1')}; data = [('image',('upscale_input.jpg', image_bytes.getvalue(), 'image/jpeg'))]
|
13 |
|
14 |
try:
|
15 |
+
progress(0.95, desc="Upscaling image...")
|
16 |
+
response = requests.post(mode['upscale'], headers=head, data=payload, files=data, timeout=(60, 60))
|
17 |
|
18 |
if len(response.content) < 65 * 1024:
|
19 |
print(reject())
|
modules/input_configs.py
CHANGED
@@ -14,35 +14,13 @@ ratio = {
|
|
14 |
quality = [
|
15 |
'Original',
|
16 |
'Enhanced',
|
|
|
17 |
'Enhanced and Upscaled'
|
18 |
]
|
19 |
|
20 |
-
|
21 |
-
'
|
22 |
-
'
|
23 |
-
'
|
24 |
-
'
|
25 |
-
|
26 |
-
'tiling',
|
27 |
-
'poorly drawn hands',
|
28 |
-
'poorly drawn feet',
|
29 |
-
'poorly drawn face',
|
30 |
-
'out of frame',
|
31 |
-
'extra limbs',
|
32 |
-
'disfigured',
|
33 |
-
'deformed',
|
34 |
-
'body out of frame',
|
35 |
-
'bad anatomy',
|
36 |
-
'watermark',
|
37 |
-
'signature',
|
38 |
-
'cut off',
|
39 |
-
'low contrast',
|
40 |
-
'underexposed',
|
41 |
-
'overexposed',
|
42 |
-
'bad art',
|
43 |
-
'beginner',
|
44 |
-
'amateur',
|
45 |
-
'distorted face'
|
46 |
-
]
|
47 |
-
|
48 |
-
negative_v1 = ', '.join(negative_list)
|
|
|
14 |
quality = [
|
15 |
'Original',
|
16 |
'Enhanced',
|
17 |
+
'Upscaled',
|
18 |
'Enhanced and Upscaled'
|
19 |
]
|
20 |
|
21 |
+
smart = [
|
22 |
+
'Disabled',
|
23 |
+
'Fusion',
|
24 |
+
'Expansion',
|
25 |
+
'Fusion and Expansion'
|
26 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules/models_anime.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
ckpt_anime = {
|
2 |
-
'Anime
|
3 |
-
'Anime
|
4 |
-
'Anime
|
5 |
'Meina Mix': '116',
|
6 |
'Orange Mix': '103',
|
7 |
'Rev Animated': '112',
|
|
|
1 |
ckpt_anime = {
|
2 |
+
'Anime V1-a': '120',
|
3 |
+
'Anime V1-b': '121',
|
4 |
+
'Anime V1-c': '21',
|
5 |
'Meina Mix': '116',
|
6 |
'Orange Mix': '103',
|
7 |
'Rev Animated': '112',
|
modules/service_configs.py
CHANGED
@@ -1,53 +1,23 @@
|
|
1 |
-
import gradio as ui; from datetime import datetime; import logging
|
|
|
2 |
|
3 |
# enable debug
|
4 |
logging.basicConfig(level=logging.DEBUG)
|
5 |
|
6 |
# global theme
|
7 |
theme = ui.themes.Default(
|
8 |
-
font=[ui.themes.GoogleFont('
|
9 |
-
text_size=ui.themes.Size(lg="
|
10 |
primary_hue='rose', secondary_hue='rose', neutral_hue='zinc', radius_size=ui.themes.sizes.radius_none)
|
11 |
|
12 |
-
css = '''
|
13 |
-
footer {
|
14 |
-
display: none !important;
|
15 |
-
}
|
16 |
-
|
17 |
-
div.svelte-vt1mxs>*, div.svelte-vt1mxs>.form > * {
|
18 |
-
border: none;
|
19 |
-
}
|
20 |
-
|
21 |
-
.app.svelte-182fdeq.svelte-182fdeq {
|
22 |
-
padding: 0px !important;
|
23 |
-
}
|
24 |
-
|
25 |
-
.grid-wrap.svelte-hpz95u.svelte-hpz95u {
|
26 |
-
overflow-y: auto !important;
|
27 |
-
}
|
28 |
-
|
29 |
-
.selected.svelte-1uw5tnk {
|
30 |
-
background: #262629 !important;
|
31 |
-
}
|
32 |
-
|
33 |
-
.closed.svelte-g7pfx4>button.svelte-g7pfx4 {
|
34 |
-
display: none !important;
|
35 |
-
}
|
36 |
-
|
37 |
-
gradio-app {
|
38 |
-
background: none !important;
|
39 |
-
}
|
40 |
-
|
41 |
-
input.svelte-1f354aw.svelte-1f354aw, textarea.svelte-1f354aw.svelte-1f354aw {
|
42 |
-
text-align: justify !important;
|
43 |
-
}
|
44 |
-
'''
|
45 |
-
|
46 |
# global locale - english
|
47 |
success = 'That worked successfully!'
|
48 |
single_error = 'That did not work!'
|
49 |
quads_error = 'Some images cannot be processed!'
|
50 |
empty_error = 'Prompt field cannot be empty!'
|
|
|
|
|
|
|
51 |
received = 'Request Received'
|
52 |
timed = 'Request Timeout'
|
53 |
rejected = 'Request Error/Rejected'
|
@@ -60,12 +30,14 @@ spholder2 = 'Things to get rid of!'
|
|
60 |
spholder3 = 'Put wonders into the generated prompt!'
|
61 |
sprompt = 'Generate images of:'
|
62 |
sprompt1 = 'Based on image, create:'
|
|
|
63 |
smodel = 'Using the AI model:'
|
64 |
smode = 'Using the mode:'
|
65 |
sratio = 'In the size of:'
|
66 |
sstyle = 'Inspired by the style of:'
|
67 |
squality = 'At a quality level of:'
|
68 |
snumber = 'With a quantity of:'
|
|
|
69 |
|
70 |
# global function
|
71 |
def timestamp(): return f"[{datetime.now().strftime('%d/%m/%y at %H:%M:%S')}]"
|
@@ -75,4 +47,235 @@ def reject(): return f"{timestamp()} \U0000274C {rejected}"
|
|
75 |
def done(): return f"{timestamp()} \U0001F618 {complete}"
|
76 |
def header(feature): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 5px">{feature}</h4></center>')
|
77 |
def footer(): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 0px">{liability}<br></h4>{rights}</center>')
|
78 |
-
def title(feature): return f"{feature}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as ui; from datetime import datetime; import logging, requests, json, random
|
2 |
+
from modules.service_endpoints import *; import numpy as np
|
3 |
|
4 |
# enable debug
|
5 |
logging.basicConfig(level=logging.DEBUG)
|
6 |
|
7 |
# global theme
|
8 |
theme = ui.themes.Default(
|
9 |
+
font=[ui.themes.GoogleFont('IBM Plex Sans Condensed')], font_mono=[ui.themes.GoogleFont('IBM Plex Sans Condensed')],
|
10 |
+
text_size=ui.themes.Size(lg="18px", md="18px", sm="18px", xl="18px", xs="18px", xxl="18px", xxs="18px"),
|
11 |
primary_hue='rose', secondary_hue='rose', neutral_hue='zinc', radius_size=ui.themes.sizes.radius_none)
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# global locale - english
|
14 |
success = 'That worked successfully!'
|
15 |
single_error = 'That did not work!'
|
16 |
quads_error = 'Some images cannot be processed!'
|
17 |
empty_error = 'Prompt field cannot be empty!'
|
18 |
+
pf_error = 'Prompt fusion error. Proceeding...'
|
19 |
+
pe_error = 'Prompt expansion error. Proceeding...'
|
20 |
+
pe_cmd = '(The prompt must intricately describe every part of the image in concrete, objective detail. THINK about what the end goal of the description is, and extrapolate that to what would make satisfying images.)'
|
21 |
received = 'Request Received'
|
22 |
timed = 'Request Timeout'
|
23 |
rejected = 'Request Error/Rejected'
|
|
|
30 |
spholder3 = 'Put wonders into the generated prompt!'
|
31 |
sprompt = 'Generate images of:'
|
32 |
sprompt1 = 'Based on image, create:'
|
33 |
+
sprompt2 = 'Based on image, it shows:'
|
34 |
smodel = 'Using the AI model:'
|
35 |
smode = 'Using the mode:'
|
36 |
sratio = 'In the size of:'
|
37 |
sstyle = 'Inspired by the style of:'
|
38 |
squality = 'At a quality level of:'
|
39 |
snumber = 'With a quantity of:'
|
40 |
+
ssmart = 'Using SmartPromptβ’ mode:'
|
41 |
|
42 |
# global function
|
43 |
def timestamp(): return f"[{datetime.now().strftime('%d/%m/%y at %H:%M:%S')}]"
|
|
|
47 |
def done(): return f"{timestamp()} \U0001F618 {complete}"
|
48 |
def header(feature): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 5px">{feature}</h4></center>')
|
49 |
def footer(): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 0px">{liability}<br></h4>{rights}</center>')
|
50 |
+
def title(feature): return f"{feature}"
|
51 |
+
|
52 |
+
# seed generator
|
53 |
+
max_seed = np.iinfo(np.int32).max
|
54 |
+
|
55 |
+
def seeds(a, i: ui.SelectData):
|
56 |
+
print(f"Seed mode: {a}")
|
57 |
+
if i.value == 'Fixed': return ui.Slider(value=random.randint(0, max_seed), visible=True)
|
58 |
+
else: return ui.Slider(visible=False)
|
59 |
+
|
60 |
+
# prompt fusion to en
|
61 |
+
def translate(fusion, progress=ui.Progress()):
|
62 |
+
progress(0.05, desc="Initiating fusion")
|
63 |
+
try: print(f"{receive()} -> {fusion}"); return requests.get(f"{mode['fusion']}{fusion}", timeout=15).json()[0][0]
|
64 |
+
except Exception as e: print(pf_error, e); return fusion
|
65 |
+
|
66 |
+
# prompt expander
|
67 |
+
def expand(expand, progress=ui.Progress()):
|
68 |
+
progress(0.10, desc="Initiating expansion")
|
69 |
+
# return str(input)
|
70 |
+
head = {'Content-Type': 'application/json'}
|
71 |
+
body = json.dumps({"sentence": f"{expand} {pe_cmd}", "target_word_count": 30})
|
72 |
+
# body = json.dumps({"topic": input, "word_count": 30, "writing_mode": "Simple", "story_genre": "Descriptive"}) # ['story']
|
73 |
+
try: print(f"{receive()} -> {expand}"); return requests.post(url=mode['expander'], headers=head, data=body, timeout=15).json()['expanded_sentence']
|
74 |
+
except Exception as e: print(pe_error, e); return expand
|
75 |
+
|
76 |
+
# global head script
|
77 |
+
jsx = '''
|
78 |
+
<script>
|
79 |
+
window.onbeforeunload = function (event) {
|
80 |
+
event.returnValue = "Are you sure you want to leave?";
|
81 |
+
};
|
82 |
+
</script>
|
83 |
+
'''
|
84 |
+
|
85 |
+
# specific css modifiers
|
86 |
+
adj = '''
|
87 |
+
/* remove layers button */
|
88 |
+
.layer-wrap.svelte-g7pfx4.svelte-g7pfx4 {
|
89 |
+
display: none !important;
|
90 |
+
}
|
91 |
+
'''
|
92 |
+
|
93 |
+
adj2 = '''
|
94 |
+
.grid-wrap.svelte-hpz95u.svelte-hpz95u {
|
95 |
+
height: 49.8vh;
|
96 |
+
}
|
97 |
+
'''
|
98 |
+
|
99 |
+
# global css modifiers
|
100 |
+
css = '''
|
101 |
+
/* remove scrollbars */
|
102 |
+
::-webkit-scrollbar {
|
103 |
+
display: none;
|
104 |
+
}
|
105 |
+
|
106 |
+
::-webkit-scrollbar-button {
|
107 |
+
display: none;
|
108 |
+
}
|
109 |
+
|
110 |
+
body {
|
111 |
+
-ms-overflow-style: none;
|
112 |
+
}
|
113 |
+
|
114 |
+
/* remove footer */
|
115 |
+
footer {
|
116 |
+
display: none !important;
|
117 |
+
}
|
118 |
+
|
119 |
+
/* remove all padding */
|
120 |
+
.app.svelte-182fdeq.svelte-182fdeq {
|
121 |
+
padding: 0px;
|
122 |
+
}
|
123 |
+
|
124 |
+
/* remove scroll bar in gallery */
|
125 |
+
.grid-wrap.svelte-hpz95u.svelte-hpz95u {
|
126 |
+
overflow-y: auto;
|
127 |
+
}
|
128 |
+
|
129 |
+
/* remove background */
|
130 |
+
gradio-app {
|
131 |
+
background: none !important;
|
132 |
+
}
|
133 |
+
|
134 |
+
/* remove borders for tabs*/
|
135 |
+
div.svelte-iyf88w {
|
136 |
+
border: 0px;
|
137 |
+
}
|
138 |
+
|
139 |
+
/* remove padding for tabs */
|
140 |
+
div.svelte-19hvt5v {
|
141 |
+
padding: 0px;
|
142 |
+
border: 0px;
|
143 |
+
}
|
144 |
+
|
145 |
+
/* remove borders for tab button bottom*/
|
146 |
+
.tab-nav.svelte-1uw5tnk {
|
147 |
+
border: 0px;
|
148 |
+
}
|
149 |
+
|
150 |
+
/* remove borders for tab button*/
|
151 |
+
button.svelte-1uw5tnk {
|
152 |
+
border: 0px;
|
153 |
+
}
|
154 |
+
|
155 |
+
/* modify container padding and bg */
|
156 |
+
.hide-container.svelte-90oupt {
|
157 |
+
padding: var(--block-padding);
|
158 |
+
background: var(--block-background-fill);
|
159 |
+
}
|
160 |
+
|
161 |
+
/* set brush to red */
|
162 |
+
span.svelte-btgkrd {
|
163 |
+
background: rgb(255 0 0 / 60%);
|
164 |
+
}
|
165 |
+
|
166 |
+
/* remove example symbol */
|
167 |
+
svg.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno {
|
168 |
+
display: none;
|
169 |
+
}
|
170 |
+
|
171 |
+
/* replace selected tab color */
|
172 |
+
.selected.svelte-1uw5tnk {
|
173 |
+
background: #27272a;
|
174 |
+
}
|
175 |
+
|
176 |
+
/* justify textbox */
|
177 |
+
input.svelte-1f354aw.svelte-1f354aw,
|
178 |
+
textarea.svelte-1f354aw.svelte-1f354aw {
|
179 |
+
text-align: justify;
|
180 |
+
}
|
181 |
+
|
182 |
+
/* modify feature text */
|
183 |
+
label.float.svelte-1b6s6s {
|
184 |
+
padding-left: 10px;
|
185 |
+
padding-top: 6px;
|
186 |
+
}
|
187 |
+
|
188 |
+
/* change feature background */
|
189 |
+
label.svelte-1b6s6s {
|
190 |
+
background: #27272a;
|
191 |
+
}
|
192 |
+
|
193 |
+
/* remove feature icon */
|
194 |
+
span.svelte-1b6s6s {
|
195 |
+
display: none;
|
196 |
+
}
|
197 |
+
|
198 |
+
/* remove options line */
|
199 |
+
div.svelte-sfqy0y {
|
200 |
+
background: none;
|
201 |
+
}
|
202 |
+
|
203 |
+
/* modify layer button */
|
204 |
+
.layer-wrap.svelte-g7pfx4.svelte-g7pfx4 {
|
205 |
+
background: #27272a;
|
206 |
+
}
|
207 |
+
|
208 |
+
/* modify slider color */
|
209 |
+
.dark, .light {
|
210 |
+
--slider-color: var(--color-accent);
|
211 |
+
}
|
212 |
+
|
213 |
+
/* chanhe num input padding and height */
|
214 |
+
input[type="number"].svelte-pjtc3.svelte-pjtc3 {
|
215 |
+
padding: var(--checkbox-label-padding);
|
216 |
+
height: 45px;
|
217 |
+
}
|
218 |
+
|
219 |
+
/* disable anti-aliasing on gallery thumb */
|
220 |
+
.thumbnail-lg.svelte-hpz95u>img {
|
221 |
+
image-rendering: auto;
|
222 |
+
}
|
223 |
+
|
224 |
+
/* disable anti-aliasing on gallery view */
|
225 |
+
.image-button.svelte-hpz95u img {
|
226 |
+
image-rendering: auto;
|
227 |
+
}
|
228 |
+
|
229 |
+
/* make gallery buttons bigger */
|
230 |
+
.icon-buttons.svelte-hpz95u.svelte-hpz95u {
|
231 |
+
scale: 2;
|
232 |
+
padding-top: 8px;
|
233 |
+
padding-right: 15px;
|
234 |
+
}
|
235 |
+
|
236 |
+
/* make img clear btn bigger */
|
237 |
+
div.svelte-s6ybro {
|
238 |
+
scale: 2;
|
239 |
+
padding-right: 5px;
|
240 |
+
padding-top: 5px;
|
241 |
+
}
|
242 |
+
|
243 |
+
/* make img dload btn bigger */
|
244 |
+
.icon-buttons.svelte-1l6wqyv {
|
245 |
+
top: 8px;
|
246 |
+
right: 8px;
|
247 |
+
scale: 2;
|
248 |
+
padding-right: 5px;
|
249 |
+
padding-top: 5px;
|
250 |
+
}
|
251 |
+
|
252 |
+
/* remove bg completely */
|
253 |
+
body {
|
254 |
+
background: none !important;
|
255 |
+
}
|
256 |
+
|
257 |
+
/* wide mode */
|
258 |
+
.app.svelte-182fdeq.svelte-182fdeq {
|
259 |
+
max-width: 100% !important;
|
260 |
+
}
|
261 |
+
|
262 |
+
/* make prompt consistant */
|
263 |
+
label.svelte-1f354aw.svelte-1f354aw {
|
264 |
+
padding: 12px;
|
265 |
+
}
|
266 |
+
|
267 |
+
/* remove accord label */
|
268 |
+
.label-wrap.open.svelte-s1r2yt {
|
269 |
+
display: none;
|
270 |
+
}
|
271 |
+
|
272 |
+
/* make empty gallery taller */
|
273 |
+
.unpadded_box.svelte-1oiin9d {
|
274 |
+
min-height: 50vh;
|
275 |
+
}
|
276 |
+
|
277 |
+
/* make image contain */
|
278 |
+
.image-frame.svelte-rrgd5g img {
|
279 |
+
object-fit: contain;
|
280 |
+
}
|
281 |
+
'''
|
modules/service_endpoints.py
CHANGED
@@ -2,7 +2,8 @@ import os
|
|
2 |
|
3 |
mode = {
|
4 |
'generate' : os.getenv('generate'),
|
5 |
-
'upscale' : os.getenv('upscale')
|
|
|
6 |
}
|
7 |
|
8 |
head = {
|
|
|
2 |
|
3 |
mode = {
|
4 |
'generate' : os.getenv('generate'),
|
5 |
+
'upscale' : os.getenv('upscale'),
|
6 |
+
'fusion' : os.getenv('fusion')
|
7 |
}
|
8 |
|
9 |
head = {
|