piyushgrover commited on
Commit
e80da04
·
verified ·
1 Parent(s): 613f51c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +8 -5
  2. utils.py +5 -3
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from PIL import Image
3
  import random
4
 
5
- from utils import load_learned_embeds, style_guide
6
 
7
  def generate_output_image(query, selection):
8
  """Simulates an output image generation based on query and selection."""
@@ -25,7 +25,7 @@ def check_visibility(query, selection):
25
 
26
  def ui():
27
  with gr.Blocks() as demo:
28
- gr.Markdown("## Image Selection & Query-Based Search")
29
 
30
  # First Block: Displaying Images with Labels
31
 
@@ -36,18 +36,21 @@ def ui():
36
  for i in range(6):
37
  image = f'./examples/{i}.png'
38
  if i == 0:
39
- label = 'Image Sharpness Loss'
40
  else:
41
  label = style_guide[i-1][0]
42
 
43
  with gr.Column():
44
- gr.Image(value=image, label=f"{label}")
 
 
 
45
  #gr.Textbox(value=f"Label {label}", interactive=False)
46
 
47
  # Second Block: Query Input and Dropdown
48
  with gr.Row():
49
  query_input = gr.Textbox(label="Enter Query")
50
- dropdown = gr.Dropdown(['None', "Sharpness Loss", 'Oil Style', 'Matrix Style', 'Stripe Style','Dreamy Painting Style','Polygon HD Style'],
51
  label="Select Option")
52
 
53
  # Dynamic Search Button (Initially Hidden)
 
2
  from PIL import Image
3
  import random
4
 
5
+ from utils import load_learned_embeds, style_guide, IMAGE_SIZE
6
 
7
  def generate_output_image(query, selection):
8
  """Simulates an output image generation based on query and selection."""
 
25
 
26
  def ui():
27
  with gr.Blocks() as demo:
28
+ gr.Markdown("## Image Generation using Stable Diffusion")
29
 
30
  # First Block: Displaying Images with Labels
31
 
 
36
  for i in range(6):
37
  image = f'./examples/{i}.png'
38
  if i == 0:
39
+ label = 'Sharpness Loss (Additional Guidance)'
40
  else:
41
  label = style_guide[i-1][0]
42
 
43
  with gr.Column():
44
+ gr.Image(value=image, label=f"{label}",
45
+ height=IMAGE_SIZE,
46
+ show_download_button=False,
47
+ show_share_button=False)
48
  #gr.Textbox(value=f"Label {label}", interactive=False)
49
 
50
  # Second Block: Query Input and Dropdown
51
  with gr.Row():
52
  query_input = gr.Textbox(label="Enter Query")
53
+ dropdown = gr.Dropdown(['None', "Sharpness Loss (Additional Guidance)", 'Oil Style', 'Matrix Style', 'Stripe Style','Dreamy Painting Style','Polygon HD Style'],
54
  label="Select Option")
55
 
56
  # Dynamic Search Button (Initially Hidden)
utils.py CHANGED
@@ -7,6 +7,7 @@ from tqdm.auto import tqdm
7
  from transformers import CLIPTextModel, CLIPTokenizer, logging
8
  import os
9
  import torch.nn.functional as F
 
10
 
11
  style_guide = [
12
  ('Oil Style', 'oilstyle_learned_embeds.bin'),
@@ -16,6 +17,7 @@ style_guide = [
16
  ('Polygon HD Style', 'lowpolyhd_learned_embeds.bin')
17
  ]
18
 
 
19
 
20
  # Prep Scheduler
21
  def set_timesteps(scheduler, num_inference_steps):
@@ -78,11 +80,11 @@ def get_output_embeds(input_embeddings):
78
 
79
 
80
  def generate_with_embs(text_embeddings, add_guidance_loss=None, add_guidance_loss_scale=200):
81
- height = 512 # default height of Stable Diffusion
82
- width = 512 # default width of Stable Diffusion
83
  num_inference_steps = 30 # Number of denoising steps
84
  guidance_scale = 7.5 # Scale for classifier-free guidance
85
- generator = torch.manual_seed(32) # Seed generator to create the inital latent noise
86
  batch_size = 1
87
 
88
  max_length = text_embeddings.shape[1]
 
7
  from transformers import CLIPTextModel, CLIPTokenizer, logging
8
  import os
9
  import torch.nn.functional as F
10
+ import random
11
 
12
  style_guide = [
13
  ('Oil Style', 'oilstyle_learned_embeds.bin'),
 
17
  ('Polygon HD Style', 'lowpolyhd_learned_embeds.bin')
18
  ]
19
 
20
+ IMAGE_SIZE = 224
21
 
22
  # Prep Scheduler
23
  def set_timesteps(scheduler, num_inference_steps):
 
80
 
81
 
82
  def generate_with_embs(text_embeddings, add_guidance_loss=None, add_guidance_loss_scale=200):
83
+ height = IMAGE_SIZE # default height of Stable Diffusion
84
+ width = IMAGE_SIZE # default width of Stable Diffusion
85
  num_inference_steps = 30 # Number of denoising steps
86
  guidance_scale = 7.5 # Scale for classifier-free guidance
87
+ generator = torch.manual_seed(random.randint(1, 10000)) # Seed generator to create the inital latent noise
88
  batch_size = 1
89
 
90
  max_length = text_embeddings.shape[1]