HemaAM commited on
Commit
24277b9
1 Parent(s): d315355
Files changed (2) hide show
  1. app.py +12 -24
  2. utils.py +5 -1
app.py CHANGED
@@ -1,39 +1,27 @@
1
  import gradio as gr
2
  from utils import *
3
 
4
- styles_mapping = {
5
- "Illustration Style": '<illustration-style>', "Line Art":'<line-art>',
6
- "Hitokomoru Style":'<hitokomoru-style-nao>', "Marc Allante": '<Marc_Allante>',
7
- "Midjourney":'<midjourney-style>', "Hanfu Anime": '<hanfu-anime-style>',
8
- "Birb Style": '<birb-style>'
9
- }
10
- with gr.Blocks() as interface:
11
  #gr.HTML(value=HTML_TEMPLATE, show_label=False)
12
  with gr.Row():
13
  text_input = gr.Textbox(
14
  label="Enter your prompt",
15
- placeholder="Cats fighting on the road.....",
16
  )
17
  concept_dropdown = gr.Dropdown(
18
  label="Select a Concept",
19
- choices=["Illustration Style", "Line Art", "Hitokomoru Style", "Marc Allante", "Midjourney", "Hanfu Anime", "Birb Style"],
20
- value='Marc Allante'
 
21
  )
22
 
23
  method_dropdown = gr.Dropdown(
24
  label="Select Guidance Type",
25
  choices=["edge", "contrast", "sharpness", "blue", "brightness"],
26
- value='Contrast'
27
  )
28
 
29
- seed_slider = gr.Slider(
30
- label="Random Seed",
31
- minimum=0,
32
- maximum=2000,
33
- step=1,
34
- value=42
35
- )
36
- inputs = [text_input, concept_dropdown, method_dropdown, seed_slider]
37
 
38
  with gr.Row():
39
  outputs = gr.Gallery(
@@ -41,13 +29,13 @@ with gr.Blocks() as interface:
41
  columns=[2], rows=[1], object_fit="contain"
42
  )
43
 
44
- with gr.Row():
45
- button = gr.Button("Generate Image")
46
- button.click(show_image, inputs=inputs, outputs=outputs)
47
-
48
  with gr.Row():
49
  gr.Examples(examples=get_examples(), inputs=inputs, outputs=outputs, fn=show_image, cache_examples=True)
50
 
 
 
 
 
51
 
52
  if __name__ == "__main__":
53
- interface.launch(enable_queue=True)
 
1
  import gradio as gr
2
  from utils import *
3
 
4
+ with gr.Blocks() as gr_interface:
 
 
 
 
 
 
5
  #gr.HTML(value=HTML_TEMPLATE, show_label=False)
6
  with gr.Row():
7
  text_input = gr.Textbox(
8
  label="Enter your prompt",
9
+ placeholder="Cats fighting on the road ",
10
  )
11
  concept_dropdown = gr.Dropdown(
12
  label="Select a Concept",
13
+ choices=["Illustration Style", "Line Art", "Hitokomoru Style",
14
+ "Marc Allante", "Midjourney", "Hanfu Anime", "Birb Style"],
15
+ value="Illustration Style"
16
  )
17
 
18
  method_dropdown = gr.Dropdown(
19
  label="Select Guidance Type",
20
  choices=["edge", "contrast", "sharpness", "blue", "brightness"],
21
+ value="contrast"
22
  )
23
 
24
+ inputs = [text_input, concept_dropdown, method_dropdown]
 
 
 
 
 
 
 
25
 
26
  with gr.Row():
27
  outputs = gr.Gallery(
 
29
  columns=[2], rows=[1], object_fit="contain"
30
  )
31
 
 
 
 
 
32
  with gr.Row():
33
  gr.Examples(examples=get_examples(), inputs=inputs, outputs=outputs, fn=show_image, cache_examples=True)
34
 
35
+ title = "Generative Art - Stable Diffusion with Styles and Custom Loss"
36
+ demo = gr.Interface(fn=show_image, inputs=inputs, outputs=outputs, examples=get_examples(), title=title)
37
+
38
+
39
 
40
  if __name__ == "__main__":
41
+ demo.launch(enable_queue=True, debug=True)
utils.py CHANGED
@@ -126,7 +126,11 @@ def latents_to_pil(latents):
126
 
127
  def show_image(prompt, concept, guidance_type, seed):
128
 
129
- prompt = f"{prompt} in the style of {styles_mapping[concept]}"
 
 
 
 
130
  styled_image_without_loss = latents_to_pil(generate_image(seed, prompt, guidance_type, loss_flag=False))
131
  styled_image_with_loss = latents_to_pil(generate_image(seed, prompt, guidance_type, loss_flag=True))
132
  return([styled_image_without_loss, styled_image_with_loss])
 
126
 
127
  def show_image(prompt, concept, guidance_type, seed):
128
 
129
+ for idx, sd in enumerate(styles_mapping.keys()):
130
+ if(sd == concept):
131
+ break
132
+ seed = seed_list[idx]
133
+ prompt = f"{prompt} in the style of {styles_mapping[sd]}"
134
  styled_image_without_loss = latents_to_pil(generate_image(seed, prompt, guidance_type, loss_flag=False))
135
  styled_image_with_loss = latents_to_pil(generate_image(seed, prompt, guidance_type, loss_flag=True))
136
  return([styled_image_without_loss, styled_image_with_loss])