Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -124,7 +124,7 @@ def enhance_prompt(input_prompt, model_choice):
|
|
124 |
|
125 |
return enhanced_text
|
126 |
|
127 |
-
def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
128 |
if randomize_seed:
|
129 |
seed = random.randint(0, MAX_SEED)
|
130 |
|
@@ -137,13 +137,14 @@ def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height,
|
|
137 |
num_inference_steps=num_inference_steps,
|
138 |
width=width,
|
139 |
height=height,
|
|
|
140 |
generator=generator
|
141 |
).images[0]
|
142 |
|
143 |
return image, seed
|
144 |
|
145 |
@spaces.GPU
|
146 |
-
def process_workflow(image, text_prompt, vlm_model_choice, use_enhancer, model_choice, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
147 |
if image is not None:
|
148 |
# Convert image to PIL if it's not already
|
149 |
if not isinstance(image, Image.Image):
|
@@ -159,7 +160,7 @@ def process_workflow(image, text_prompt, vlm_model_choice, use_enhancer, model_c
|
|
159 |
if use_enhancer:
|
160 |
prompt = enhance_prompt(prompt, model_choice)
|
161 |
|
162 |
-
generated_image, used_seed = generate_image(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps)
|
163 |
|
164 |
return generated_image, prompt, used_seed
|
165 |
|
@@ -197,7 +198,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue", secondar
|
|
197 |
with gr.Column(scale=1):
|
198 |
with gr.Group(elem_classes="input-group"):
|
199 |
input_image = gr.Image(label="Input Image (VLM Captioner)")
|
200 |
-
vlm_model_choice = gr.Radio(["
|
201 |
|
202 |
with gr.Accordion("Advanced Settings", open=False):
|
203 |
text_prompt = gr.Textbox(label="Text Prompt (optional, used if no image is uploaded)")
|
@@ -210,6 +211,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue", secondar
|
|
210 |
height = gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024)
|
211 |
guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=20.0, step=0.5, value=5.0)
|
212 |
num_inference_steps = gr.Slider(label="Inference Steps", minimum=20, maximum=50, step=1, value=20)
|
|
|
213 |
|
214 |
generate_btn = gr.Button("Generate Image", elem_classes="submit-btn")
|
215 |
|
@@ -223,7 +225,8 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue", secondar
|
|
223 |
fn=process_workflow,
|
224 |
inputs=[
|
225 |
input_image, text_prompt, vlm_model_choice, use_enhancer, model_choice,
|
226 |
-
negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps
|
|
|
227 |
],
|
228 |
outputs=[output_image, final_prompt, used_seed]
|
229 |
)
|
|
|
124 |
|
125 |
return enhanced_text
|
126 |
|
127 |
+
def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images_per_prompt):
|
128 |
if randomize_seed:
|
129 |
seed = random.randint(0, MAX_SEED)
|
130 |
|
|
|
137 |
num_inference_steps=num_inference_steps,
|
138 |
width=width,
|
139 |
height=height,
|
140 |
+
num_images_per_prompt=num_images_per_prompt,
|
141 |
generator=generator
|
142 |
).images[0]
|
143 |
|
144 |
return image, seed
|
145 |
|
146 |
@spaces.GPU
|
147 |
+
def process_workflow(image, text_prompt, vlm_model_choice, use_enhancer, model_choice, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images_per_prompt):
|
148 |
if image is not None:
|
149 |
# Convert image to PIL if it's not already
|
150 |
if not isinstance(image, Image.Image):
|
|
|
160 |
if use_enhancer:
|
161 |
prompt = enhance_prompt(prompt, model_choice)
|
162 |
|
163 |
+
generated_image, used_seed = generate_image(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images_per_prompt)
|
164 |
|
165 |
return generated_image, prompt, used_seed
|
166 |
|
|
|
198 |
with gr.Column(scale=1):
|
199 |
with gr.Group(elem_classes="input-group"):
|
200 |
input_image = gr.Image(label="Input Image (VLM Captioner)")
|
201 |
+
vlm_model_choice = gr.Radio(["Florence-2", "Long Captioner"], label="VLM Model", value="Florence-2")
|
202 |
|
203 |
with gr.Accordion("Advanced Settings", open=False):
|
204 |
text_prompt = gr.Textbox(label="Text Prompt (optional, used if no image is uploaded)")
|
|
|
211 |
height = gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024)
|
212 |
guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=20.0, step=0.5, value=5.0)
|
213 |
num_inference_steps = gr.Slider(label="Inference Steps", minimum=20, maximum=50, step=1, value=20)
|
214 |
+
num_images_per_prompt = gr.Slider(1, 4, 1, step=1, label="Number of images per prompt")
|
215 |
|
216 |
generate_btn = gr.Button("Generate Image", elem_classes="submit-btn")
|
217 |
|
|
|
225 |
fn=process_workflow,
|
226 |
inputs=[
|
227 |
input_image, text_prompt, vlm_model_choice, use_enhancer, model_choice,
|
228 |
+
negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
|
229 |
+
num_images_per_prompt
|
230 |
],
|
231 |
outputs=[output_image, final_prompt, used_seed]
|
232 |
)
|