Spaces:
Build error
Build error
File size: 7,455 Bytes
71f4839 e6b7912 7695918 71f4839 7695918 e6b7912 7695918 b51e7a3 7695918 71f4839 e6b7912 7695918 e6b7912 7695918 e6b7912 71f4839 e6b7912 71f4839 e6b7912 71f4839 b13358d 71f4839 661bc0c 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
import gradio as ui; from datetime import datetime; import logging, requests, json, random
from modules.service_endpoints import *; import numpy as np
# enable debug
logging.basicConfig(level=logging.DEBUG)
# global theme
theme = ui.themes.Default(
font=[ui.themes.GoogleFont('IBM Plex Sans Condensed')], font_mono=[ui.themes.GoogleFont('IBM Plex Sans Condensed')],
text_size=ui.themes.Size(lg="18px", md="18px", sm="18px", xl="18px", xs="18px", xxl="18px", xxs="18px"),
primary_hue='rose', secondary_hue='rose', neutral_hue='zinc', radius_size=ui.themes.sizes.radius_none)
# global locale - english
success = 'That worked successfully!'
single_error = 'That did not work!'
queue_error = 'Some images cannot be processed!'
empty_error = 'Prompt field cannot be empty!'
pf_error = 'Prompt fusion error. Proceeding...'
pe_error = 'Prompt expansion error. Proceeding...'
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.)'
received = 'Request Received'
timed = 'Request Timeout'
rejected = 'Request Error/Rejected'
complete = 'Request Completed'
liability = 'STELLA can make mistakes and inaccuracies.'
rights = '© 2023-2024 Ikmal Said. All rights reserved.'
spholder = 'Imagine a person, place or anything!'
spholder1 = 'Elements to add into the image!'
spholder2 = 'Things to get rid of!'
spholder3 = 'Put wonders into the generated prompt!'
sprompt = 'Generate images of:'
sprompt1 = 'Based on image, create:'
sprompt2 = 'Based on image, it shows:'
smodel = 'Using the AI model:'
smode = 'Using the mode:'
sratio = 'In the size of:'
sstyle = 'Inspired by the style of:'
squality = 'At a quality level of:'
snumber = 'With a quantity of:'
ssmart = 'Using SmartPrompt™ mode:'
# global function
def timestamp(): return f"[{datetime.now().strftime('%d/%m/%y at %H:%M:%S')}]"
def receive(): return f"{timestamp()} \U0001F680 {received}"
def timeout(): return f"{timestamp()} \U000023F0 {timed}"
def reject(): return f"{timestamp()} \U0000274C {rejected}"
def done(): return f"{timestamp()} \U0001F618 {complete}"
def header(feature): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 5px">{feature}</h4></center>')
def footer(): ui.HTML(f'<center><h4 style="font-size: 1em; margin: 5px 0px 0px">{liability}<br></h4>{rights}</center>')
def title(feature): return f"{feature}"
# seed generator
max_seed = np.iinfo(np.int32).max
def seeds(a, i: ui.SelectData):
print(f"Seed mode: {a}")
if i.value == 'Fixed': return ui.Slider(value=random.randint(0, max_seed), visible=True)
else: return ui.Slider(visible=False)
# prompt fusion to en
def translate(fusion, progress=ui.Progress()):
progress(0.05, desc="Initiating fusion")
try: print(f"{receive()} -> {fusion}"); return requests.get(f"{mode['fusion']}{fusion}", timeout=15).json()[0][0]
except Exception as e: print(pf_error, e); return fusion
# prompt expander
def expand(expand, progress=ui.Progress()):
progress(0.10, desc="Initiating expansion")
# return str(input)
head = {'Content-Type': 'application/json'}
body = json.dumps({"sentence": f"{expand} {pe_cmd}", "target_word_count": 30})
# body = json.dumps({"topic": input, "word_count": 30, "writing_mode": "Simple", "story_genre": "Descriptive"}) # ['story']
try: print(f"{receive()} -> {expand}"); return requests.post(url=mode['expander'], headers=head, data=body, timeout=15).json()['expanded_sentence']
except Exception as e: print(pe_error, e); return expand
# global head script
jsx = '''
<script>
window.onbeforeunload = function (event) {
event.returnValue = "Are you sure you want to leave?";
};
</script>
'''
# specific css modifiers
adj = '''
/* remove layers button */
.layer-wrap.svelte-g7pfx4.svelte-g7pfx4 {
display: none !important;
}
'''
adj2 = '''
.grid-wrap.svelte-hpz95u.svelte-hpz95u {
height: 49.8vh;
}
'''
# global css modifiers
css = '''
/* remove scrollbars */
::-webkit-scrollbar {
display: none;
}
::-webkit-scrollbar-button {
display: none;
}
body {
-ms-overflow-style: none;
}
/* remove footer */
footer {
display: none !important;
}
/* remove all padding */
.app.svelte-182fdeq.svelte-182fdeq {
padding: 0px;
}
/* remove scroll bar in gallery */
.grid-wrap.svelte-hpz95u.svelte-hpz95u {
overflow-y: auto;
}
/* remove background */
gradio-app {
background: #27272a !important;
}
/* remove borders for tabs*/
div.svelte-iyf88w {
border: 0px;
}
/* remove padding for tabs */
div.svelte-19hvt5v {
padding: 0px;
border: 0px;
}
/* remove borders for tab button bottom*/
.tab-nav.svelte-1uw5tnk {
border: 0px;
}
/* remove borders for tab button*/
button.svelte-1uw5tnk {
border: 0px;
}
/* modify container padding and bg */
.hide-container.svelte-90oupt {
padding: var(--block-padding);
background: var(--block-background-fill);
}
/* set brush to red */
span.svelte-btgkrd {
background: rgb(255 0 0 / 60%);
}
/* remove example symbol */
svg.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno {
display: none;
}
/* replace selected tab color */
.selected.svelte-1uw5tnk {
background: #27272a;
}
/* justify textbox */
input.svelte-1f354aw.svelte-1f354aw,
textarea.svelte-1f354aw.svelte-1f354aw {
text-align: justify;
}
/* modify feature text */
label.float.svelte-1b6s6s {
padding-left: 10px;
padding-top: 6px;
}
/* change feature background */
label.svelte-1b6s6s {
background: #27272a;
}
/* remove feature icon */
span.svelte-1b6s6s {
display: none;
}
/* remove options line */
div.svelte-sfqy0y {
background: none;
}
/* modify layer button */
.layer-wrap.svelte-g7pfx4.svelte-g7pfx4 {
background: #27272a;
}
/* modify slider color */
.dark, .light {
--slider-color: var(--color-accent);
}
/* chanhe num input padding and height */
input[type="number"].svelte-pjtc3.svelte-pjtc3 {
padding: var(--checkbox-label-padding);
height: 45px;
}
/* disable anti-aliasing on gallery thumb */
.thumbnail-lg.svelte-hpz95u>img {
image-rendering: auto;
}
/* disable anti-aliasing on gallery view */
.image-button.svelte-hpz95u img {
image-rendering: auto;
}
/* make gallery buttons bigger */
.icon-buttons.svelte-hpz95u.svelte-hpz95u {
scale: 2;
padding-top: 8px;
padding-right: 15px;
}
/* make img clear btn bigger */
div.svelte-s6ybro {
scale: 2;
padding-right: 5px;
padding-top: 5px;
}
/* make img dload btn bigger */
.icon-buttons.svelte-1l6wqyv {
top: 8px;
right: 8px;
scale: 2;
padding-right: 5px;
padding-top: 5px;
}
/* remove bg completely */
body {
background: none !important;
}
/* wide mode */
.app.svelte-182fdeq.svelte-182fdeq {
max-width: 100% !important;
}
/* make prompt consistant */
label.svelte-1f354aw.svelte-1f354aw {
padding: 12px;
}
/* remove accord label */
.label-wrap.open.svelte-s1r2yt {
display: none;
}
/* make empty gallery taller */
.unpadded_box.svelte-1oiin9d {
min-height: 50vh;
}
/* make image contain */
.image-frame.svelte-rrgd5g img {
object-fit: contain;
}
''' |