Update app.py
Browse files
app.py
CHANGED
@@ -37,18 +37,42 @@ def update_imgbox(choices):
|
|
37 |
choices_plus = extend_choices(choices)
|
38 |
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
39 |
|
|
|
40 |
def gen_fn(model_str, prompt):
|
41 |
if model_str == 'NA':
|
42 |
return None
|
|
|
|
|
|
|
|
|
|
|
43 |
noise = str(randint(0, 9999))
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
def make_me():
|
47 |
# with gr.Tab('The Dream'):
|
48 |
with gr.Row():
|
49 |
txt_input = gr.Textbox(lines=2, value=kii, width=300, max_height=100)
|
50 |
#txt_input = gr.Textbox(label='Your prompt:', lines=2, value=kii)
|
51 |
-
|
52 |
gen_button = gr.Button('Generate images', width=150, height=30)
|
53 |
stop_button = gr.Button('Stop', variant='secondary', interactive=False, width=150, height=30)
|
54 |
gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
|
@@ -62,7 +86,7 @@ def make_me():
|
|
62 |
output = [gr.Image(label=m, min_width=170, height=170) for m in default_models]
|
63 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
64 |
for m, o in zip(current_models, output):
|
65 |
-
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
66 |
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
67 |
with gr.Accordion('Model selection'):
|
68 |
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)
|
@@ -78,18 +102,24 @@ def make_me():
|
|
78 |
|
79 |
|
80 |
js_code = """
|
81 |
-
|
82 |
-
|
83 |
-
|
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 |
-
|
90 |
-
|
91 |
-
|
92 |
|
93 |
|
94 |
-
demo.queue(concurrency_count=
|
95 |
demo.launch()
|
|
|
37 |
choices_plus = extend_choices(choices)
|
38 |
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
39 |
|
40 |
+
def gen_fn(model_str, prompt, negative_prompt):
|
41 |
def gen_fn(model_str, prompt):
|
42 |
if model_str == 'NA':
|
43 |
return None
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
noise = str(randint(0, 9999))
|
50 |
+
combined_prompt = f'{prompt} {model_str} {negative_prompt} {noise}'
|
51 |
+
print(f"Generating with prompt: {combined_prompt}") # Debug line
|
52 |
+
|
53 |
+
# result = models_load[model_str](f'{prompt} {negative_prompt} {noise}')
|
54 |
+
|
55 |
+
# end_time = time.time() # End timing
|
56 |
+
# runtime = end_time - start_time
|
57 |
+
# model_timings[model_str] = runtime # Log the model's execution time
|
58 |
+
|
59 |
+
# queue_size -= 1 # Decrement queue size after processing
|
60 |
+
# return f"Model {model_str} ran for {runtime:.2f} seconds", result
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
return models_load[model_str](f'{prompt} {negative_prompt} {noise}')
|
67 |
+
|
68 |
+
|
69 |
|
70 |
def make_me():
|
71 |
# with gr.Tab('The Dream'):
|
72 |
with gr.Row():
|
73 |
txt_input = gr.Textbox(lines=2, value=kii, width=300, max_height=100)
|
74 |
#txt_input = gr.Textbox(label='Your prompt:', lines=2, value=kii)
|
75 |
+
negative_prompt_input = gr.Textbox(lines=2, value="", label="Negative Prompt", width=300, max_height=100)
|
76 |
gen_button = gr.Button('Generate images', width=150, height=30)
|
77 |
stop_button = gr.Button('Stop', variant='secondary', interactive=False, width=150, height=30)
|
78 |
gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
|
|
|
86 |
output = [gr.Image(label=m, min_width=170, height=170) for m in default_models]
|
87 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
88 |
for m, o in zip(current_models, output):
|
89 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input, negative_prompt_input], o)
|
90 |
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
91 |
with gr.Accordion('Model selection'):
|
92 |
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)
|
|
|
102 |
|
103 |
|
104 |
js_code = """
|
105 |
+
<script>
|
106 |
+
const originalScroll = window.scrollTo;
|
107 |
+
const originalShowToast = gradio.Toast.show;
|
108 |
+
gradio.Toast.show = function() {
|
109 |
+
originalShowToast.apply(this, arguments);
|
110 |
+
window.scrollTo = function() {};};
|
111 |
+
setTimeout(() => {
|
112 |
+
window.scrollTo = originalScroll;
|
113 |
+
}, 300000); // Restore scroll function after 3 seconds
|
114 |
+
</script>
|
115 |
"""
|
116 |
|
117 |
|
118 |
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:
|
119 |
+
gr.Markdown("<div></div>")
|
120 |
+
make_me()
|
121 |
+
gr.Markdown(js_code)
|
122 |
|
123 |
|
124 |
+
demo.queue(concurrency_count=50)
|
125 |
demo.launch()
|