Spaces:
Runtime error
Runtime error
Update app.py
Browse filesAdded Negative Prompting
app.py
CHANGED
|
@@ -33,7 +33,7 @@ def update_imgbox(choices):
|
|
| 33 |
choices_plus = extend_choices(choices)
|
| 34 |
return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
|
| 35 |
|
| 36 |
-
def gen_fn(model_str, prompt, max_retries=10):
|
| 37 |
if model_str == 'NA':
|
| 38 |
return None
|
| 39 |
|
|
@@ -41,7 +41,7 @@ def gen_fn(model_str, prompt, max_retries=10):
|
|
| 41 |
while retries < max_retries:
|
| 42 |
try:
|
| 43 |
noise = str(randint(0, 9999999))
|
| 44 |
-
result = models_load[model_str](f'{prompt} {noise}')
|
| 45 |
return result
|
| 46 |
except Exception as e:
|
| 47 |
print(f"Error generating image: {e}")
|
|
@@ -55,6 +55,7 @@ def make_me():
|
|
| 55 |
with gr.Row():
|
| 56 |
with gr.Column(scale=1):
|
| 57 |
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
|
|
|
| 58 |
with gr.Row():
|
| 59 |
gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
|
| 60 |
stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
|
@@ -72,7 +73,7 @@ def make_me():
|
|
| 72 |
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
|
| 73 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
| 74 |
for m, o in zip(current_models, output):
|
| 75 |
-
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
| 76 |
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
|
| 77 |
|
| 78 |
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|
|
@@ -120,7 +121,7 @@ body {
|
|
| 120 |
box-sizing: border-box;
|
| 121 |
margin-bottom: 20px;
|
| 122 |
}
|
| 123 |
-
.custom_textbox {
|
| 124 |
background-color: #2d343f;
|
| 125 |
border: 1px solid #3b4252;
|
| 126 |
color: #7f8184;
|
|
@@ -227,7 +228,7 @@ body {
|
|
| 227 |
margin: 0;
|
| 228 |
padding: 10px;
|
| 229 |
}
|
| 230 |
-
.custom_textbox
|
| 231 |
width: 100%;
|
| 232 |
box-sizing: border-box;
|
| 233 |
}
|
|
|
|
| 33 |
choices_plus = extend_choices(choices)
|
| 34 |
return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
|
| 35 |
|
| 36 |
+
def gen_fn(model_str, prompt, negative_prompt, max_retries=10):
|
| 37 |
if model_str == 'NA':
|
| 38 |
return None
|
| 39 |
|
|
|
|
| 41 |
while retries < max_retries:
|
| 42 |
try:
|
| 43 |
noise = str(randint(0, 9999999))
|
| 44 |
+
result = models_load[model_str](f'{prompt} {noise}', negative_prompt=negative_prompt)
|
| 45 |
return result
|
| 46 |
except Exception as e:
|
| 47 |
print(f"Error generating image: {e}")
|
|
|
|
| 55 |
with gr.Row():
|
| 56 |
with gr.Column(scale=1):
|
| 57 |
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
| 58 |
+
negative_txt_input = gr.Textbox(label='Negative prompt:', lines=3, container=False, elem_id="custom_negative_textbox", placeholder="Negative Prompt")
|
| 59 |
with gr.Row():
|
| 60 |
gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
|
| 61 |
stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
|
|
|
| 73 |
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
|
| 74 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
| 75 |
for m, o in zip(current_models, output):
|
| 76 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input, negative_txt_input], o)
|
| 77 |
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
|
| 78 |
|
| 79 |
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|
|
|
|
| 121 |
box-sizing: border-box;
|
| 122 |
margin-bottom: 20px;
|
| 123 |
}
|
| 124 |
+
.custom_textbox, .custom_negative_textbox {
|
| 125 |
background-color: #2d343f;
|
| 126 |
border: 1px solid #3b4252;
|
| 127 |
color: #7f8184;
|
|
|
|
| 228 |
margin: 0;
|
| 229 |
padding: 10px;
|
| 230 |
}
|
| 231 |
+
.custom_textbox, .custom_negative_textbox, .custom_image, .custom_checkbox_group {
|
| 232 |
width: 100%;
|
| 233 |
box-sizing: border-box;
|
| 234 |
}
|