Spaces:
Sleeping
Sleeping
added/updated app files
Browse files- README.md +1 -1
- app.py β app_v2.py +14 -10
- modules/engine_upscale_alt.py +3 -11
- modules/engine_v2.py +33 -35
- modules/input_configs.py +7 -29
- modules/models_v2.py +5 -3
- modules/service_configs.py +241 -38
- modules/service_endpoints.py +3 -1
README.md
CHANGED
@@ -5,7 +5,7 @@ colorFrom: pink
|
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.20.1
|
8 |
-
app_file:
|
9 |
pinned: false
|
10 |
license: agpl-3.0
|
11 |
---
|
|
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.20.1
|
8 |
+
app_file: app_v2.py
|
9 |
pinned: false
|
10 |
license: agpl-3.0
|
11 |
---
|
app.py β app_v2.py
RENAMED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
feature = 'Text-to-Image - V2 / V3'
|
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_v2 = ui.Gallery(label=title(feature), object_fit="contain", height="
|
17 |
-
prompt_v2 = ui.Textbox(
|
18 |
with ui.Row():
|
19 |
clear_v2 = ui.ClearButton(value="Reset", components=[result_v2, prompt_v2])
|
20 |
submit_v2= ui.Button("Submit", variant="primary")
|
21 |
|
22 |
-
with ui.Accordion('
|
23 |
style_v2 = ui.Dropdown(label=sstyle, choices=list(stella_v2.keys()), value='None', filterable=False)
|
24 |
-
model_v2 = ui.Dropdown(label=smodel, choices=list(ckpt_v2.keys()), value='
|
25 |
ratio_v2 = ui.Dropdown(label=sratio, choices=list(ratio.keys()), value='Square (1:1)', filterable=False)
|
26 |
quality_v2 = ui.Dropdown(label=squality, choices=quality, value='Enhanced', filterable=False)
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
-
process_v2 = submit_v2.click(fn=quads_v2, inputs=[prompt_v2, model_v2, style_v2, ratio_v2, quality_v2,
|
30 |
-
prompt_v2.submit(fn=quads_v2, inputs=[prompt_v2, model_v2, style_v2, ratio_v2, quality_v2,
|
|
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
-
stella.queue(default_concurrency_limit=100
|
|
|
1 |
+
from modules.engine_v2 import *
|
2 |
feature = 'Text-to-Image - V2 / V3'
|
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_v2 = ui.Gallery(label=title(feature), object_fit="contain", height="98vh", show_share_button=False)
|
17 |
+
prompt_v2 = ui.Textbox(label=sprompt, placeholder=spholder)
|
18 |
with ui.Row():
|
19 |
clear_v2 = ui.ClearButton(value="Reset", components=[result_v2, prompt_v2])
|
20 |
submit_v2= ui.Button("Submit", variant="primary")
|
21 |
|
22 |
+
with ui.Accordion('More options'):
|
23 |
style_v2 = ui.Dropdown(label=sstyle, choices=list(stella_v2.keys()), value='None', filterable=False)
|
24 |
+
model_v2 = ui.Dropdown(label=smodel, choices=list(ckpt_v2.keys()), value='Creative V3', filterable=False)
|
25 |
ratio_v2 = ui.Dropdown(label=sratio, choices=list(ratio.keys()), value='Square (1:1)', filterable=False)
|
26 |
quality_v2 = ui.Dropdown(label=squality, choices=quality, value='Enhanced', filterable=False)
|
27 |
+
smart_v2 = ui.Dropdown(label=ssmart, choices=smart, value='Disabled', filterable=False)
|
28 |
+
with ui.Row():
|
29 |
+
seedtype_v2 = ui.Dropdown(label='Seed type:', choices=['Randomized', 'Fixed'], value='Randomized', filterable=False)
|
30 |
+
seedno_v2 = ui.Number(label='Seed value:', value=0, minimum=0, maximum=max_seed, visible=False)
|
31 |
|
32 |
+
process_v2 = submit_v2.click(fn=quads_v2, inputs=[prompt_v2, model_v2, style_v2, ratio_v2, quality_v2, smart_v2, seedtype_v2, seedno_v2], outputs=[result_v2, result_v2])
|
33 |
+
prompt_v2.submit(fn=quads_v2, inputs=[prompt_v2, model_v2, style_v2, ratio_v2, quality_v2, smart_v2, seedtype_v2, seedno_v2], outputs=[result_v2, result_v2])
|
34 |
+
seedtype_v2.select(fn=seeds, inputs=seedtype_v2, outputs=seedno_v2)
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
+
stella.queue(default_concurrency_limit=100).launch(inbrowser=True, favicon_path="favicon.ico")
|
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/engine_v2.py
CHANGED
@@ -1,40 +1,36 @@
|
|
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_v2 import *
|
11 |
from modules.models_v2 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_v2(prompt, model, style, size, quality):
|
20 |
prompt = stella_v2[style]['prompt'].format(prompt=prompt)
|
21 |
-
negative_v2 = stella_v2[style]['negative_prompt']
|
|
|
|
|
22 |
|
23 |
print(f"{receive()} -> {prompt}")
|
24 |
-
|
25 |
data = {
|
26 |
'model_version': (None, '1'),
|
27 |
'prompt': (None, prompt),
|
28 |
'style_id': (None, ckpt_v2[str(model)]),
|
29 |
-
'negative_prompt': (None,
|
30 |
'aspect_ratio': (None, ratio[str(size)]),
|
31 |
'high_res_results': (None, '1'),
|
32 |
'cfg': (None, '9.5'),
|
33 |
'priority': (None, '1'),
|
|
|
34 |
}
|
35 |
|
36 |
try:
|
37 |
-
response = requests.post(mode['generate'], headers=head, files=data, timeout=
|
38 |
|
39 |
if len(response.content) < 65 * 1024:
|
40 |
print(reject())
|
@@ -67,7 +63,12 @@ def gen_v2(prompt, model, style, size, quality):
|
|
67 |
).enhance(1.05)
|
68 |
).enhance(1.05)
|
69 |
return upscale(better2)
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
71 |
else:
|
72 |
print("original -> raw output")
|
73 |
original = Image.open(BytesIO(response.content))
|
@@ -82,24 +83,28 @@ def gen_v2(prompt, model, style, size, quality):
|
|
82 |
ui.Warning(message=single_error)
|
83 |
return None
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
result_list = [None] * quantities
|
92 |
percent = 0
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
95 |
futures = []
|
96 |
|
97 |
for i in range(quantities):
|
98 |
-
future = executor.submit(lambda x: gen_v2(a, b, c, d, e), i)
|
99 |
futures.append(future)
|
100 |
-
multiplier = 0.
|
101 |
percent += multiplier
|
102 |
-
progress(percent, desc=f"
|
103 |
time.sleep(0.25)
|
104 |
|
105 |
for i, future in enumerate(futures):
|
@@ -107,13 +112,6 @@ def quads_v2(a, b, c, d, e, f, progress=ui.Progress()):
|
|
107 |
result_list[i] = result
|
108 |
|
109 |
successful_results = [result for result in result_list if result is not None]
|
110 |
-
|
111 |
-
if
|
112 |
-
|
113 |
-
ui.Warning(message=single_error)
|
114 |
-
else:
|
115 |
-
ui.Warning(message=quads_error)
|
116 |
-
else:
|
117 |
-
pass
|
118 |
-
|
119 |
-
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_v2 import *
|
7 |
from modules.models_v2 import *
|
8 |
from modules.service_configs import *
|
9 |
from modules.engine_upscale_alt import *
|
10 |
+
from gradio_client import Client
|
11 |
|
12 |
+
def gen_v2(prompt, model, style, size, quality, seed_type, seed_num):
|
|
|
|
|
|
|
|
|
13 |
prompt = stella_v2[style]['prompt'].format(prompt=prompt)
|
14 |
+
# negative_v2 = stella_v2[style]['negative_prompt']
|
15 |
+
if seed_type == 'Randomized': seed_number = random.randint(0, max_seed)
|
16 |
+
else: seed_number = seed_num
|
17 |
|
18 |
print(f"{receive()} -> {prompt}")
|
19 |
+
|
20 |
data = {
|
21 |
'model_version': (None, '1'),
|
22 |
'prompt': (None, prompt),
|
23 |
'style_id': (None, ckpt_v2[str(model)]),
|
24 |
+
'negative_prompt': (None, 'hands, face, eyes, legs'),
|
25 |
'aspect_ratio': (None, ratio[str(size)]),
|
26 |
'high_res_results': (None, '1'),
|
27 |
'cfg': (None, '9.5'),
|
28 |
'priority': (None, '1'),
|
29 |
+
'seed': (None, str(seed_number))
|
30 |
}
|
31 |
|
32 |
try:
|
33 |
+
response = requests.post(mode['generate'], headers=head, files=data, timeout=(60, 60))
|
34 |
|
35 |
if len(response.content) < 65 * 1024:
|
36 |
print(reject())
|
|
|
63 |
).enhance(1.05)
|
64 |
).enhance(1.05)
|
65 |
return upscale(better2)
|
66 |
+
|
67 |
+
if quality == 'Upscaled':
|
68 |
+
print("better3 -> upscaled output")
|
69 |
+
better3 = Image.open(BytesIO(response.content))
|
70 |
+
return upscale(better3)
|
71 |
+
|
72 |
else:
|
73 |
print("original -> raw output")
|
74 |
original = Image.open(BytesIO(response.content))
|
|
|
83 |
ui.Warning(message=single_error)
|
84 |
return None
|
85 |
|
86 |
+
def quads_v2(a, b, c, d, e, f, g, h, progress=ui.Progress()):
|
87 |
+
if g == 'Randomized': quantities = 2
|
88 |
+
else: quantities = 1
|
89 |
+
|
90 |
+
if b == 'Lightning': quantities = 1
|
91 |
+
|
92 |
result_list = [None] * quantities
|
93 |
percent = 0
|
94 |
+
|
95 |
+
if f == 'Fusion': a = translate(a)
|
96 |
+
if f == 'Expansion': a = expand(a)
|
97 |
+
if f == 'Fusion and Expansion': a = expand(translate(a))
|
98 |
+
|
99 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
100 |
futures = []
|
101 |
|
102 |
for i in range(quantities):
|
103 |
+
future = executor.submit(lambda x: gen_v2(a, b, c, d, e, g, h), i)
|
104 |
futures.append(future)
|
105 |
+
multiplier = 0.95 / quantities
|
106 |
percent += multiplier
|
107 |
+
progress(percent, desc=f"Generating results")
|
108 |
time.sleep(0.25)
|
109 |
|
110 |
for i, future in enumerate(futures):
|
|
|
112 |
result_list[i] = result
|
113 |
|
114 |
successful_results = [result for result in result_list if result is not None]
|
115 |
+
|
116 |
+
if g == 'Randomized': return successful_results, ui.Gallery(columns=1, rows=2)
|
117 |
+
else: return successful_results, ui.Gallery(columns=1, rows=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_v2.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
ckpt_v2 = {
|
|
|
2 |
'Anime V2': '34',
|
3 |
'Toon V2': '36',
|
4 |
'Realistic V2': '124',
|
5 |
-
'Creative
|
6 |
-
'Creative
|
7 |
'Toon V3': '39',
|
|
|
8 |
'Realistic V3': '12000',
|
9 |
-
'SDXL': '122'
|
10 |
}
|
|
|
1 |
ckpt_v2 = {
|
2 |
+
'Lightning': '',
|
3 |
'Anime V2': '34',
|
4 |
'Toon V2': '36',
|
5 |
'Realistic V2': '124',
|
6 |
+
'Creative V2-a': '33',
|
7 |
+
'Creative V2-b': '35',
|
8 |
'Toon V3': '39',
|
9 |
+
'Creative V3': '126',
|
10 |
'Realistic V3': '12000',
|
11 |
+
'SDXL': '122'
|
12 |
}
|
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,9 @@ 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 |
+
'expander' : os.getenv('expander')
|
8 |
}
|
9 |
|
10 |
head = {
|