gaur3009 commited on
Commit
e7ff32b
·
verified ·
1 Parent(s): 622ad8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -93
app.py CHANGED
@@ -1,53 +1,6 @@
1
  import gradio as gr
2
- import numpy as np
3
- import random
4
- from diffusers import DiffusionPipeline
5
- import torch
6
  from PIL import Image, ImageOps, ImageEnhance
7
 
8
- device = "cuda" if torch.cuda.is_available() else "cpu"
9
-
10
- if torch.cuda.is_available():
11
- torch.cuda.max_memory_allocated(device=device)
12
- pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
13
- pipe.enable_xformers_memory_efficient_attention()
14
- pipe = pipe.to(device)
15
- else:
16
- pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
17
- pipe = pipe.to(device)
18
-
19
- MAX_SEED = np.iinfo(np.int32).max
20
- MAX_IMAGE_SIZE = 1024
21
-
22
- def infer(prompt_part1, color, dress_type, front_design, back_design, prompt_part5, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
23
- front_prompt = f"front view of {prompt_part1} {color} colored plain {dress_type} with {front_design} design, {prompt_part5}"
24
- back_prompt = f"back view of {prompt_part1} {color} colored plain {dress_type} with {back_design} design, {prompt_part5}"
25
-
26
- if randomize_seed:
27
- seed = random.randint(0, MAX_SEED)
28
-
29
- generator = torch.Generator().manual_seed(seed)
30
-
31
- front_image = pipe(
32
- prompt=front_prompt,
33
- guidance_scale=guidance_scale,
34
- num_inference_steps=num_inference_steps,
35
- width=width,
36
- height=height,
37
- generator=generator
38
- ).images[0]
39
-
40
- back_image = pipe(
41
- prompt=back_prompt,
42
- guidance_scale=guidance_scale,
43
- num_inference_steps=num_inference_steps,
44
- width=width,
45
- height=height,
46
- generator=generator
47
- ).images[0]
48
-
49
- return front_image, back_image
50
-
51
  def edit_image(img_data, operation, *args):
52
  image = Image.open(img_data)
53
 
@@ -72,63 +25,27 @@ def edit_image(img_data, operation, *args):
72
  return image
73
 
74
  examples = [
75
- ["red", "t-shirt", "yellow stripes", "polka dots"],
76
- ["blue", "hoodie", "minimalist", "abstract art"],
77
- ["red", "sweat shirt", "geometric design", "plain"],
78
  ]
79
 
80
- if torch.cuda.is_available():
81
- power_device = "GPU"
82
- else:
83
- power_device = "CPU"
84
-
85
  with gr.Blocks() as demo:
86
  with gr.Row():
87
- gr.Markdown(f"""
88
- # GenZ Couture
89
- Currently running on {power_device}.
90
- """)
91
 
92
  with gr.Row():
93
  with gr.Column():
94
- prompt_part1 = gr.Textbox(value="a single", label="Prompt Part 1")
95
- prompt_part2 = gr.Textbox(label="Color", placeholder="Color (e.g., red, blue)")
96
- prompt_part3 = gr.Textbox(label="Dress Type", placeholder="Dress Type (e.g., t-shirt, hoodie)")
97
- prompt_part4_front = gr.Textbox(label="Front Design", placeholder="Front Design")
98
- prompt_part4_back = gr.Textbox(label="Back Design", placeholder="Back Design")
99
- prompt_part5 = gr.Textbox(value="hanging on the plain wall", label="Prompt Part 5")
100
- seed = gr.Slider(0, MAX_SEED, step=1, label="Seed", value=42)
101
- randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
102
- width = gr.Slider(256, MAX_IMAGE_SIZE, step=32, label="Width", value=512)
103
- height = gr.Slider(256, MAX_IMAGE_SIZE, step=32, label="Height", value=512)
104
- guidance_scale = gr.Slider(1, 20, step=0.5, label="Guidance Scale", value=7.5)
105
- num_inference_steps = gr.Slider(10, 100, step=1, label="Number of Inference Steps", value=50)
106
-
107
- run_button = gr.Button("Generate Designs")
108
-
109
- with gr.Column():
110
- front_result = gr.Image(label="Front View Result", type="pil", interactive=True)
111
- back_result = gr.Image(label="Back View Result", type="pil", interactive=True)
112
-
113
- run_button.click(
114
- fn=infer,
115
- inputs=[prompt_part1, prompt_part2, prompt_part3, prompt_part4_front, prompt_part4_back, prompt_part5, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
116
- outputs=[front_result, back_result]
117
- )
118
-
119
- gr.Markdown("## Creative Touch")
120
-
121
- with gr.Row():
122
- edit_operation = gr.Dropdown(choices=["rotate", "crop", "resize", "flip", "color"], label="Edit Operation")
123
- edit_args = gr.Textbox(label="Edit Arguments (comma-separated)", placeholder="For rotate: angle, For crop: left,top,right,bottom, For resize: width,height, For flip: horizontal/vertical, For color: factor")
124
 
125
- edit_button = gr.Button("Edit Front Design")
126
- edited_image = gr.Image(label="Edited Front Design", type="pil", interactive=True)
127
 
128
  edit_button.click(
129
  fn=lambda img_data, operation, args: edit_image(img_data, operation, *args.split(',')),
130
- inputs=[front_result, edit_operation, edit_args],
131
  outputs=[edited_image]
132
  )
133
 
134
- demo.queue().launch()
 
1
  import gradio as gr
 
 
 
 
2
  from PIL import Image, ImageOps, ImageEnhance
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def edit_image(img_data, operation, *args):
5
  image = Image.open(img_data)
6
 
 
25
  return image
26
 
27
  examples = [
28
+ ["rotate", "90", "crop", "100,100,400,400"],
29
+ ["resize", "400,400", "flip", "horizontal"],
30
+ ["color", "1.5"]
31
  ]
32
 
 
 
 
 
 
33
  with gr.Blocks() as demo:
34
  with gr.Row():
35
+ gr.Markdown("# Image Editor")
 
 
 
36
 
37
  with gr.Row():
38
  with gr.Column():
39
+ edit_operation = gr.Dropdown(choices=["rotate", "crop", "resize", "flip", "color"], label="Edit Operation")
40
+ edit_args = gr.Textbox(label="Edit Arguments (comma-separated)", placeholder="For rotate: angle, For crop: left,top,right,bottom, For resize: width,height, For flip: horizontal/vertical, For color: factor")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ edit_button = gr.Button("Edit Image")
43
+ edited_image = gr.Image(label="Edited Image", type="pil", interactive=True)
44
 
45
  edit_button.click(
46
  fn=lambda img_data, operation, args: edit_image(img_data, operation, *args.split(',')),
47
+ inputs=[edited_image, edit_operation, edit_args],
48
  outputs=[edited_image]
49
  )
50
 
51
+ demo.queue().launch()