Spaces:
Runtime error
Runtime error
File size: 12,443 Bytes
c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c cb94fa3 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c 46d8cd4 c324d8c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
import gradio as gr
from torchvision import transforms
import torch
from main_inference import generate_mixed_image, generate_image
from style_guidence import generate_with_prompt_style
import matplotlib.colors as mcolors
style_file_maps = {
'3D Female Cyborgs':"style_embeddings/3d_female_cyborgs.bin",
'80s Anime':"style_embeddings/80s_anime.bin",
'Anders Zorn':"style_embeddings/anders_zorn.bin",
"Angus Mcbride":"style_embeddings/angus_mcbride.bin",
"Breack Core":"style_embeddings/breakcore.bin",
"Brittney Williams":"style_embeddings/brittney_williams.bin",
"Bull vs Bear":"style_embeddings/bull_vs_bear.bin",
"Caitlin FairChild":"style_embeddings/caitlin_fairchild.bin",
"Exodus Styling":"style_embeddings/exodus_styling.bin",
"FoorByv2":"style_embeddings/foorbyv2.bin"
}
def run_generate_mixed_image(prompt1,prompt2,num_of_inf_steps,noised_image):
image = generate_mixed_image(prompt1,prompt2,num_of_inf_steps,noised_image)
return image
def run_generate_image(prompt1,num_of_inf_steps,noise_checkbox):
image = generate_image(prompt1,num_inference_steps=num_of_inf_steps,noised_image=noise_checkbox)
return image
def run_generate_image_with_color_doninance(prompt1,color,color_loss_scale,num_of_inf_steps,noised_image_checkbox_1):
# Convert the hexadecimal color code to RGB values
rgba_color = mcolors.hex2color(color)
# Multiply the RGB values by 255 to get them in the [0, 255] range
rgb_values = [int(val * 255) for val in rgba_color]
image = generate_image(prompt1,num_of_inf_steps,True,rgb_values,color_loss_scale,noised_image_checkbox_1)
return image
def run_generate_image_with_style(prompt,style,num_of_inf_steps):
output = generate_with_prompt_style(prompt, style_file_maps[style],num_of_inf_steps)
return output
description_text_to_image = """ ### Text to Image Generation
1. Write a Text Prompt and number of inference steps, the more the better results but execution time will be high.
2. Output will be an image based on the text prompt provided.
3. Check if you want to see noised version of the image
"""
description_generate_mixed_image = """ ### Mix Image Generation
1. Write Two Text prompts and number of inference steps, the more the better results but execution time will be high.
2. Output will a image which is mix of both of the text provided.
3. Check if you want to see noised version of the image
"""
description_generate_image_with_color_dominance = """ ### Generate Images with color dominance
1. Write a Text Prompt and number of inference steps, the more the better results but execution time will be high.
2. Select a color
3. Choose Color loss value
4. Get the generated Image
5. Check if you want to see noised version of the image
"""
description_generate_prompt_with_style = """ ### Get a generated image in the selection of your style
1. Write a Text Prompt and number of inference steps, the more the better results but execution time will be high.
2. Select a style to dominate the photo
3. Get the Output
"""
# Description
title = "<center><strong><font size='8'>The Stable Diffusion</font></strong></center>"
image_input1 = gr.Image(type='pil')
image_input2 = gr.Image(type='filepath')
image_input3 = gr.Image(type='pil')
image_input4 = gr.Image(type='pil')
image_input5 = gr.Image(type='pil')
text_input = gr.Text(label="Enter Text Prompt")
text_input2 = gr.Text(label="Enter Text Prompt")
text_input3 = gr.Text(label="Enter Text Prompt")
text_input4 = gr.Text(label = "Enter Text Prompt")
text_input5 = gr.Text(label = "Enter Text Prompt")
num_of_inf_steps_slider1 = gr.inputs.Slider(minimum=0, maximum=50, default=30, step=1,label="Num of Inference Steps")
num_of_inf_steps_slider2 = gr.inputs.Slider(minimum=0, maximum=50, default=30, step=1,label="Num of Inference Steps")
num_of_inf_steps_slider3 = gr.inputs.Slider(minimum=0, maximum=50, default=30, step=1,label="Num of Inference Steps")
num_of_inf_steps_slider4 = gr.inputs.Slider(minimum=0, maximum=50, default=30, step=1,label="Num of Inference Steps")
color = gr.ColorPicker(label="Select a Color",description="Choose a color from the color picker:")
noised_image_checkbox = gr.inputs.Checkbox(default=False, label="Show Noised Image")
noised_image_checkbox_1 = gr.inputs.Checkbox(default=False, label="Show Noised Image")
noised_image_checkbox_2 = gr.inputs.Checkbox(default=False, label="Show Noised Image")
noised_image_checkbox_3 = gr.inputs.Checkbox(default=False, label="Show Noised Image")
color_loss_scale = gr.inputs.Slider(minimum=0, maximum=255, default=40, step=1,label="Color Loss")
style_options = ['3D Female Cyborgs', '80s Anime','Anders Zorn',"Angus Mcbride","Breack Core", "Brittney Williams","Bull vs Bear","Caitlin FairChild","Exodus Styling","FoorByv2"]
selected_style = gr.Dropdown(style_options,label="Select a Style to Follow",default="Anders Zorn")
css = "h1 { text-align: center } .about { text-align: justify; padding-left: 10%; padding-right: 10%; }"
with gr.Blocks(css=css, title='Play with Stable Diffusion') as demo:
with gr.Row():
with gr.Column(scale=1):
# Title
gr.Markdown(title)
with gr.Tab("Generate Image"):
# Images
with gr.Row(variant="panel"):
with gr.Column(scale=1):
text_input.render()
num_of_inf_steps_slider1.render()
noised_image_checkbox.render()
with gr.Column(scale=1):
image_input1.render()
# Submit & Clear
with gr.Row():
with gr.Column():
run_generate_image_button = gr.Button("generate_image", variant='primary')
clear_btn_text_to_image = gr.Button("Clear", variant="secondary")
gr.Markdown(description_text_to_image)
# gr.Examples(examples = ["A White cat", "a dog playing in garden", "people enjoying around sea"],
# inputs=[text_input,red_color_slider,green_color_slider,blue_color_slider,noised_image_checkbox],
# outputs=image_input1,
# fn=run_generate_image,
# cache_examples=True,
# examples_per_page=4)
run_generate_image_button.click(run_generate_image,
inputs=[text_input,num_of_inf_steps_slider1,noised_image_checkbox],
outputs=image_input1)
with gr.Tab("Generate Image with Color Dominance"):
# Images
with gr.Row(variant="panel"):
with gr.Column(scale=1):
text_input4.render()
color_loss_scale.render()
num_of_inf_steps_slider2.render()
noised_image_checkbox_1.render()
color.render()
with gr.Column(scale=1):
image_input3.render()
# Submit & Clear
with gr.Row():
with gr.Column():
run_generate_image_with_color_doninance_button = gr.Button("generate_image_with_color_doninance", variant='primary')
clear_btn_text_to_image = gr.Button("Clear", variant="secondary")
gr.Markdown(description_generate_image_with_color_dominance)
# gr.Examples(examples = ["A White cat", "a dog playing in garden", "people enjoying around sea"],
# inputs=[text_input4,red_color_slider,green_color_slider,blue_color_slider,noised_image_checkbox],
# outputs=image_input3,
# fn=run_generate_image_with_color_doninance,
# cache_examples=True,
# examples_per_page=4)
run_generate_image_with_color_doninance_button.click(run_generate_image_with_color_doninance,
inputs=[text_input4,color,color_loss_scale,num_of_inf_steps_slider2,noised_image_checkbox_1],
outputs=image_input3)
####################################################################################################################
with gr.Tab("Generate Mixed Image"):
# Images
with gr.Row(variant="panel"):
with gr.Column(scale=1):
text_input2.render()
text_input3.render()
num_of_inf_steps_slider3.render()
noised_image_checkbox_2.render()
with gr.Column(scale=1):
image_input4.render()
# Submit & Clear
with gr.Row():
with gr.Column():
run_generate_mixed_image_button = gr.Button("generate_mixed_image", variant='primary')
clear_btn_image_to_image = gr.Button("Clear", variant="secondary")
gr.Markdown(description_generate_mixed_image)
# gr.Examples(examples = ["examples/12830823_87d2654e31.jpg", "examples/27782020_4dab210360.jpg", "examples/44129946_9eeb385d77.jpg"],
# inputs=[text_input,red_color_slider_1,green_color_slider_1,blue_color_slider_1,noised_image_checkbox],
# outputs=image_input4,
# fn=run_generate_mixed_image,
# cache_examples=True,
# examples_per_page=4)
run_generate_mixed_image_button.click(run_generate_mixed_image,
inputs=[text_input2,text_input3,num_of_inf_steps_slider3,noised_image_checkbox_2],
outputs=image_input4)
####################################################################################################################
with gr.Tab("Generate Image with Style"):
# Images
with gr.Row(variant="panel"):
with gr.Column(scale=1):
text_input5.render()
num_of_inf_steps_slider4.render()
selected_style.render()
with gr.Column(scale=1):
image_input5.render()
# Submit & Clear
with gr.Row():
with gr.Column():
run_progress_video_button = gr.Button("generate_image", variant='primary')
clear_btn_progress_video = gr.Button("Clear", variant="secondary")
gr.Markdown(description_generate_prompt_with_style)
# gr.Examples(examples = ["examples/12830823_87d2654e31.jpg", "examples/27782020_4dab210360.jpg", "examples/44129946_9eeb385d77.jpg"],
# inputs=[text_input5],
# outputs=image_input5,
# fn=run_process_video,
# examples_per_page=4)
run_progress_video_button.click(run_generate_image_with_style,
inputs=[
text_input5,selected_style,num_of_inf_steps_slider4
],
outputs=image_input5)
#######################################################################################################################
#######################################################################################################################
def clear():
return None, None
def clear_text():
return None, None, None
clear_btn_text_to_image.click(clear, outputs=[image_input1, image_input1])
clear_btn_image_to_image.click(clear, outputs=[image_input2, image_input3])
clear_btn_progress_video.click(clear, outputs=[image_input2, image_input3])
demo.queue()
demo.launch(debug=True)
|