sagar007 commited on
Commit
bf7ef8a
·
verified ·
1 Parent(s): c51c238

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -115,27 +115,36 @@ def generate_image(seed, prompt, loss_type, loss_flag=False):
115
 
116
  return latents
117
 
118
- # Gradio interface function
119
- def generate_images(prompt, style, guidance_type):
120
- images = show_image(prompt, style, guidance_type)
121
- return images[0], images[1]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
- # Create Gradio interface
124
  iface = gr.Interface(
125
- fn=generate_images,
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
- gr.Image(label="Image without Loss"),
133
- gr.Image(label="Image with Loss"),
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()