Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,10 @@ from random import randint
|
|
| 3 |
from all_models import models
|
| 4 |
from datetime import datetime
|
| 5 |
|
| 6 |
-
now2 = 0
|
| 7 |
-
|
| 8 |
-
|
| 9 |
def get_current_time():
|
| 10 |
now = datetime.now()
|
| 11 |
-
now2 = now
|
| 12 |
current_time = now2.strftime("%Y-%m-%d %H:%M:%S")
|
| 13 |
-
ki = f'{current_time}'
|
| 14 |
return ki
|
| 15 |
|
| 16 |
def load_fn(models):
|
|
@@ -36,60 +32,45 @@ def update_imgbox(choices):
|
|
| 36 |
choices_plus = extend_choices(choices)
|
| 37 |
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
| 38 |
|
| 39 |
-
def gen_fn(model_str, prompt,
|
| 40 |
if model_str == 'NA':
|
| 41 |
return None
|
| 42 |
noise = str(randint(0, 9999))
|
| 43 |
-
|
| 44 |
-
neg_prompt = 'negative prompt'
|
| 45 |
-
model_func = models_load[model_str]
|
| 46 |
-
if hasattr(model_func, 'accepts_negative_prompt') and model_func.accepts_negative_prompt:
|
| 47 |
-
return model_func(prompt=prompt, noise=noise, negative_prompt=neg_prompt)
|
| 48 |
-
else:
|
| 49 |
-
return model_func(prompt=prompt, noise=noise)
|
| 50 |
|
| 51 |
def make_me():
|
| 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 |
-
gr.HTML()
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
js_code = """
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
console.log('ghgh');
|
| 84 |
-
|
| 85 |
"""
|
| 86 |
|
| 87 |
-
|
| 88 |
with gr.Blocks(css="div.float.svelte-1mwvhlq { position: absolute; top: var(--block-label-margin); left: var(--block-label-margin); background: none; border: none;}") as demo:
|
| 89 |
gr.Markdown("<script>" + js_code + "</script>")
|
| 90 |
make_me()
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
demo.queue(concurrency_count=100)
|
| 95 |
demo.launch()
|
|
|
|
| 3 |
from all_models import models
|
| 4 |
from datetime import datetime
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
def get_current_time():
|
| 7 |
now = datetime.now()
|
|
|
|
| 8 |
current_time = now2.strftime("%Y-%m-%d %H:%M:%S")
|
| 9 |
+
ki = f'{kii} {current_time}'
|
| 10 |
return ki
|
| 11 |
|
| 12 |
def load_fn(models):
|
|
|
|
| 32 |
choices_plus = extend_choices(choices)
|
| 33 |
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
| 34 |
|
| 35 |
+
def gen_fn(model_str, prompt, negative_prompt):
|
| 36 |
if model_str == 'NA':
|
| 37 |
return None
|
| 38 |
noise = str(randint(0, 9999))
|
| 39 |
+
return models_load[model_str](f'{prompt} {negative_prompt} {noise}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def make_me():
|
| 42 |
+
with gr.Row():
|
| 43 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=2, width=800, max_height=30)
|
| 44 |
+
neg_txt_input = gr.Textbox(label='Negative prompt:', lines=2, width=800, max_height=30)
|
| 45 |
+
gen_button = gr.Button('Generate images', width=30, height=30)
|
| 46 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False, width=30, height=30)
|
| 47 |
+
gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
|
| 48 |
+
gr.HTML("""
|
| 49 |
+
<div style="text-align: center; max-width: 100%; margin: 0 auto;">
|
| 50 |
+
<body>
|
| 51 |
+
</body>
|
| 52 |
+
</div>
|
| 53 |
+
""")
|
| 54 |
+
with gr.Row():
|
| 55 |
+
output = [gr.Image(label=m, min_width=250, height=250) for m in default_models]
|
| 56 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
| 57 |
+
for m, o in zip(current_models, output):
|
| 58 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input, neg_txt_input], o)
|
| 59 |
+
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
| 60 |
+
with gr.Accordion('Model selection'):
|
| 61 |
+
model_choice = gr.CheckboxGroup(models, label=f' {num_models} different models selected', value=default_models, multiselect=True, max_choices=num_models, interactive=True, filterable=False)
|
| 62 |
+
model_choice.change(update_imgbox, model_choice, output)
|
| 63 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
| 64 |
+
with gr.Row():
|
| 65 |
+
gr.HTML()
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
js_code = """
|
| 68 |
+
console.log('ghgh');
|
|
|
|
|
|
|
|
|
|
| 69 |
"""
|
| 70 |
|
|
|
|
| 71 |
with gr.Blocks(css="div.float.svelte-1mwvhlq { position: absolute; top: var(--block-label-margin); left: var(--block-label-margin); background: none; border: none;}") as demo:
|
| 72 |
gr.Markdown("<script>" + js_code + "</script>")
|
| 73 |
make_me()
|
| 74 |
|
|
|
|
|
|
|
| 75 |
demo.queue(concurrency_count=100)
|
| 76 |
demo.launch()
|