Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -115,27 +115,36 @@ def generate_image(seed, prompt, loss_type, loss_flag=False):
|
|
115 |
|
116 |
return latents
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
# Create Gradio interface
|
124 |
iface = gr.Interface(
|
125 |
-
fn=
|
126 |
inputs=[
|
127 |
gr.Textbox(label="Prompt"),
|
128 |
gr.Dropdown(list(styles_mapping.keys()), label="Style"),
|
129 |
gr.Dropdown(["blue", "edge", "contrast", "brightness", "sharpness", "saturation"], label="Guidance Type"),
|
130 |
],
|
131 |
-
outputs=
|
132 |
-
|
133 |
-
|
134 |
-
],
|
135 |
examples=get_examples(),
|
136 |
-
title="Text Inversion Image Generation",
|
137 |
-
description="Generate images using text inversion with different styles and guidance types.",
|
138 |
)
|
139 |
|
140 |
-
# Launch the app
|
141 |
iface.launch()
|
|
|
115 |
|
116 |
return latents
|
117 |
|
118 |
+
def generate_image(prompt, style, guidance_type):
|
119 |
+
styled_prompt = f"{prompt} in the style of {styles_mapping[style]}"
|
120 |
+
seed = torch.randint(0, 1000000, (1,)).item()
|
121 |
+
latents = generate_image(seed, styled_prompt, guidance_type, loss_flag=True)
|
122 |
+
with torch.no_grad():
|
123 |
+
image = sd_pipeline.decode_latents(latents)
|
124 |
+
image = sd_pipeline.numpy_to_pil(image)[0]
|
125 |
+
return image
|
126 |
+
|
127 |
+
def get_examples():
|
128 |
+
examples = [
|
129 |
+
["A bird sitting on a tree", "Midjourney", "edge"],
|
130 |
+
["Cats fighting on the road", "Marc Allante", "brightness"],
|
131 |
+
["A mouse with the head of a puppy", "Hitokomoru Style", "contrast"],
|
132 |
+
["A woman with a smiling face in front of an Italian Pizza", "Hanfu Anime", "brightness"],
|
133 |
+
["A campfire (oil on canvas)", "Birb Style", "blue"],
|
134 |
+
]
|
135 |
+
return examples
|
136 |
|
|
|
137 |
iface = gr.Interface(
|
138 |
+
fn=generate_image,
|
139 |
inputs=[
|
140 |
gr.Textbox(label="Prompt"),
|
141 |
gr.Dropdown(list(styles_mapping.keys()), label="Style"),
|
142 |
gr.Dropdown(["blue", "edge", "contrast", "brightness", "sharpness", "saturation"], label="Guidance Type"),
|
143 |
],
|
144 |
+
outputs=gr.Image(label="Generated Image"),
|
145 |
+
title="Stable Diffusion with Custom Styles",
|
146 |
+
description="Generate images using a custom Stable Diffusion model with various styles and guidance types.",
|
|
|
147 |
examples=get_examples(),
|
|
|
|
|
148 |
)
|
149 |
|
|
|
150 |
iface.launch()
|