sagar007 commited on
Commit
dfc3020
·
verified ·
1 Parent(s): dbfd4a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -8
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import PIL
2
  import torch
3
  import numpy as np
@@ -102,17 +103,19 @@ def compute_loss(original_image, loss_type):
102
  return error
103
 
104
 
 
105
  def get_examples():
106
  examples = [
107
- ['A bird sitting on a tree', 'Midjourney', 'edge', 5],
108
- ['Cats fighting on the road', 'Marc Allante', 'brightness', 65],
109
- ['A mouse with the head of a puppy', 'Hitokomoru Style', 'contrast', 110],
110
- ['A woman with a smiling face in front of an Italian Pizza', 'Hanfu Anime', 'brightness', 29],
111
- ['A campfire (oil on canvas)', 'Birb Style', 'blue', 47],
112
  ]
113
- return(examples)
114
-
115
 
 
 
116
  def latents_to_pil(latents):
117
  # bath of latents -> list of images
118
  latents = (1 / 0.18215) * latents
@@ -205,4 +208,29 @@ def generate_image(seed, prompt, loss_type, loss_flag=False):
205
 
206
  latents = scheduler.step(noise_pred,t, latents).prev_sample
207
 
208
- return latents
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  import PIL
3
  import torch
4
  import numpy as np
 
103
  return error
104
 
105
 
106
+
107
  def get_examples():
108
  examples = [
109
+ ['A bird sitting on a tree', 'Midjourney', 'edge'],
110
+ ['Cats fighting on the road', 'Marc Allante', 'brightness'],
111
+ ['A mouse with the head of a puppy', 'Hitokomoru Style', 'contrast'],
112
+ ['A woman with a smiling face in front of an Italian Pizza', 'Hanfu Anime', 'brightness'],
113
+ ['A campfire (oil on canvas)', 'Birb Style', 'blue'],
114
  ]
115
+ return examples
 
116
 
117
+ # Existing functions (latents_to_pil, show_image, generate_image)
118
+ # ... (Copy all the existing functions here)
119
  def latents_to_pil(latents):
120
  # bath of latents -> list of images
121
  latents = (1 / 0.18215) * latents
 
208
 
209
  latents = scheduler.step(noise_pred,t, latents).prev_sample
210
 
211
+ return latents
212
+
213
+ # Gradio interface function
214
+ def generate_images(prompt, style, guidance_type):
215
+ images = show_image(prompt, style, guidance_type)
216
+ return images[0], images[1]
217
+
218
+ # Create Gradio interface
219
+ iface = gr.Interface(
220
+ fn=generate_images,
221
+ inputs=[
222
+ gr.Textbox(label="Prompt"),
223
+ gr.Dropdown(list(styles_mapping.keys()), label="Style"),
224
+ gr.Dropdown(["blue", "edge", "contrast", "brightness", "sharpness", "saturation"], label="Guidance Type"),
225
+ ],
226
+ outputs=[
227
+ gr.Image(label="Image without Loss"),
228
+ gr.Image(label="Image with Loss"),
229
+ ],
230
+ examples=get_examples(),
231
+ title="Text Inversion Image Generation",
232
+ description="Generate images using text inversion with different styles and guidance types.",
233
+ )
234
+
235
+ # Launch the app
236
+ iface.launch()