Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,15 +7,10 @@ from threading import RLock
|
|
7 |
from datetime import datetime
|
8 |
|
9 |
preSetPrompt = "cute tall slender athletic 20+ caucasian woman. gorgeous face. perky tits. sensual expression. lifting shirt. photorealistic. cinematic. f1.4"
|
10 |
-
# preSetPrompt = "cute tall slender athletic 20+ nude caucasian woman. gorgeous face. perky tits. gaping outie pussy. pussy juice. sly smile. explicit pose. artistic. photorealistic. cinematic. f1.4"
|
11 |
-
|
12 |
-
# H. R. Giger prompt:
|
13 |
-
# preSetPrompt = "a tall slender athletic caucasian nude 18+ female cyborg. gorgeous face. perky tits. wet skin. sensual expression. she is entangled in rusty chains, rusty barbed wire and electric cables. old dark dusty decaying spaceship designed by h.r. giger. rusty metal dildos. wet tubes and wet plastic hoses. dark, gloomy teal cinematic light. photorealistic."
|
14 |
-
|
15 |
negPreSetPrompt = "[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, text, fuzziness"
|
16 |
|
17 |
lock = RLock()
|
18 |
-
HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None
|
19 |
|
20 |
def get_current_time():
|
21 |
now = datetime.now()
|
@@ -35,34 +30,26 @@ def load_fn(models):
|
|
35 |
m = gr.Interface(lambda: None, ['text'], ['image'])
|
36 |
models_load.update({model: m})
|
37 |
|
38 |
-
|
39 |
load_fn(models)
|
40 |
|
41 |
-
|
42 |
num_models = 6
|
43 |
max_images = 6
|
44 |
inference_timeout = 400
|
45 |
default_models = models[:num_models]
|
46 |
MAX_SEED = 2**32-1
|
47 |
|
48 |
-
|
49 |
def extend_choices(choices):
|
50 |
return choices[:num_models] + (num_models - len(choices[:num_models])) * ['NA']
|
51 |
|
52 |
-
|
53 |
def update_imgbox(choices):
|
54 |
choices_plus = extend_choices(choices[:num_models])
|
55 |
return [gr.Image(None, label=m, visible=(m!='NA')) for m in choices_plus]
|
56 |
|
57 |
-
|
58 |
def random_choices():
|
59 |
import random
|
60 |
random.seed()
|
61 |
return random.choices(models, k=num_models)
|
62 |
|
63 |
-
|
64 |
-
# https://huggingface.co/docs/api-inference/detailed_parameters
|
65 |
-
# https://huggingface.co/docs/huggingface_hub/package_reference/inference_client
|
66 |
async def infer(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, seed=-1, timeout=inference_timeout):
|
67 |
kwargs = {}
|
68 |
if height > 0: kwargs["height"] = height
|
@@ -94,16 +81,15 @@ async def infer(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0
|
|
94 |
raise Exception() from e
|
95 |
if task.done() and result is not None and not isinstance(result, tuple):
|
96 |
with lock:
|
97 |
-
# png_path = "img.png"
|
98 |
-
# png_path = get_current_time() + "_" + model_str.replace("/", "_") + ".png"
|
99 |
-
# png_path = model_str.replace("/", "_") + " - " + prompt + " - " + get_current_time() + ".png"
|
100 |
png_path = model_str.replace("/", "_") + " - " + get_current_time() + "_" + str(theSeed) + ".png"
|
101 |
image = save_image(result, png_path, model_str, prompt, nprompt, height, width, steps, cfg, seed)
|
102 |
return image
|
103 |
return None
|
104 |
|
105 |
-
|
106 |
def gen_fn(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, seed=-1):
|
|
|
|
|
|
|
107 |
try:
|
108 |
loop = asyncio.new_event_loop()
|
109 |
result = loop.run_until_complete(infer(model_str, prompt, nprompt,
|
@@ -117,16 +103,16 @@ def gen_fn(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, see
|
|
117 |
loop.close()
|
118 |
return result
|
119 |
|
120 |
-
|
121 |
def add_gallery(image, model_str, gallery):
|
122 |
-
if gallery is None:
|
|
|
|
|
|
|
123 |
with lock:
|
124 |
-
if image is not None:
|
|
|
125 |
return gallery
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
js_func = """
|
131 |
function refresh() {
|
132 |
const url = new URL(window.location);
|
@@ -150,10 +136,8 @@ js_AutoSave="""
|
|
150 |
});
|
151 |
});
|
152 |
observer.observe(img1, {attributes : true});
|
153 |
-
|
154 |
"""
|
155 |
|
156 |
-
|
157 |
CSS="""
|
158 |
.gradio-container { max-width: 1200px; margin: 0 auto; background: linear-gradient(to bottom, #1a1a1a, #2d2d2d); !important; }
|
159 |
.output {
|
@@ -193,7 +177,6 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
|
193 |
</a>""")
|
194 |
|
195 |
with gr.Column(scale=2):
|
196 |
-
# 모델 선택 부분 추가
|
197 |
with gr.Accordion("Model Selection", open=True):
|
198 |
model_choice = gr.CheckboxGroup(
|
199 |
models,
|
@@ -264,7 +247,6 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
|
264 |
rows=2
|
265 |
)
|
266 |
|
267 |
-
# 이벤트 핸들러 추가
|
268 |
model_choice.change(update_imgbox, model_choice, output)
|
269 |
model_choice.change(extend_choices, model_choice, current_models)
|
270 |
random_button.click(random_choices, None, model_choice)
|
@@ -272,12 +254,16 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
|
|
272 |
for m, o in zip(current_models, output):
|
273 |
gen_event = gr.on(
|
274 |
triggers=[gen_button.click, txt_input.submit],
|
275 |
-
fn=gen_fn,
|
276 |
-
inputs=[
|
277 |
outputs=[o],
|
278 |
concurrency_limit=None,
|
279 |
queue=False
|
280 |
)
|
281 |
-
o.change(
|
|
|
|
|
|
|
|
|
282 |
|
283 |
demo.launch(show_api=False, max_threads=400)
|
|
|
7 |
from datetime import datetime
|
8 |
|
9 |
preSetPrompt = "cute tall slender athletic 20+ caucasian woman. gorgeous face. perky tits. sensual expression. lifting shirt. photorealistic. cinematic. f1.4"
|
|
|
|
|
|
|
|
|
|
|
10 |
negPreSetPrompt = "[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, text, fuzziness"
|
11 |
|
12 |
lock = RLock()
|
13 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None
|
14 |
|
15 |
def get_current_time():
|
16 |
now = datetime.now()
|
|
|
30 |
m = gr.Interface(lambda: None, ['text'], ['image'])
|
31 |
models_load.update({model: m})
|
32 |
|
|
|
33 |
load_fn(models)
|
34 |
|
|
|
35 |
num_models = 6
|
36 |
max_images = 6
|
37 |
inference_timeout = 400
|
38 |
default_models = models[:num_models]
|
39 |
MAX_SEED = 2**32-1
|
40 |
|
|
|
41 |
def extend_choices(choices):
|
42 |
return choices[:num_models] + (num_models - len(choices[:num_models])) * ['NA']
|
43 |
|
|
|
44 |
def update_imgbox(choices):
|
45 |
choices_plus = extend_choices(choices[:num_models])
|
46 |
return [gr.Image(None, label=m, visible=(m!='NA')) for m in choices_plus]
|
47 |
|
|
|
48 |
def random_choices():
|
49 |
import random
|
50 |
random.seed()
|
51 |
return random.choices(models, k=num_models)
|
52 |
|
|
|
|
|
|
|
53 |
async def infer(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, seed=-1, timeout=inference_timeout):
|
54 |
kwargs = {}
|
55 |
if height > 0: kwargs["height"] = height
|
|
|
81 |
raise Exception() from e
|
82 |
if task.done() and result is not None and not isinstance(result, tuple):
|
83 |
with lock:
|
|
|
|
|
|
|
84 |
png_path = model_str.replace("/", "_") + " - " + get_current_time() + "_" + str(theSeed) + ".png"
|
85 |
image = save_image(result, png_path, model_str, prompt, nprompt, height, width, steps, cfg, seed)
|
86 |
return image
|
87 |
return None
|
88 |
|
|
|
89 |
def gen_fn(model_str, prompt, nprompt="", height=0, width=0, steps=0, cfg=0, seed=-1):
|
90 |
+
if model_str == 'NA':
|
91 |
+
return None
|
92 |
+
|
93 |
try:
|
94 |
loop = asyncio.new_event_loop()
|
95 |
result = loop.run_until_complete(infer(model_str, prompt, nprompt,
|
|
|
103 |
loop.close()
|
104 |
return result
|
105 |
|
|
|
106 |
def add_gallery(image, model_str, gallery):
|
107 |
+
if gallery is None:
|
108 |
+
gallery = []
|
109 |
+
if model_str == 'NA':
|
110 |
+
return gallery
|
111 |
with lock:
|
112 |
+
if image is not None:
|
113 |
+
gallery.insert(0, (image, model_str))
|
114 |
return gallery
|
115 |
|
|
|
|
|
|
|
116 |
js_func = """
|
117 |
function refresh() {
|
118 |
const url = new URL(window.location);
|
|
|
136 |
});
|
137 |
});
|
138 |
observer.observe(img1, {attributes : true});
|
|
|
139 |
"""
|
140 |
|
|
|
141 |
CSS="""
|
142 |
.gradio-container { max-width: 1200px; margin: 0 auto; background: linear-gradient(to bottom, #1a1a1a, #2d2d2d); !important; }
|
143 |
.output {
|
|
|
177 |
</a>""")
|
178 |
|
179 |
with gr.Column(scale=2):
|
|
|
180 |
with gr.Accordion("Model Selection", open=True):
|
181 |
model_choice = gr.CheckboxGroup(
|
182 |
models,
|
|
|
247 |
rows=2
|
248 |
)
|
249 |
|
|
|
250 |
model_choice.change(update_imgbox, model_choice, output)
|
251 |
model_choice.change(extend_choices, model_choice, current_models)
|
252 |
random_button.click(random_choices, None, model_choice)
|
|
|
254 |
for m, o in zip(current_models, output):
|
255 |
gen_event = gr.on(
|
256 |
triggers=[gen_button.click, txt_input.submit],
|
257 |
+
fn=lambda m=m, *args: gen_fn(m.value, *args) if m.value != 'NA' else None,
|
258 |
+
inputs=[txt_input, neg_input, height, width, steps, cfg, seed],
|
259 |
outputs=[o],
|
260 |
concurrency_limit=None,
|
261 |
queue=False
|
262 |
)
|
263 |
+
o.change(
|
264 |
+
fn=lambda img, m=m, g: add_gallery(img, m.value, g) if m.value != 'NA' else g,
|
265 |
+
inputs=[o, gallery],
|
266 |
+
outputs=[gallery]
|
267 |
+
)
|
268 |
|
269 |
demo.launch(show_api=False, max_threads=400)
|