DarianT commited on
Commit
eea3399
·
1 Parent(s): 53cc37d

Change architecture to SD2.1 and add predefined prompt lists

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -7,19 +7,23 @@ from diffusers import DiffusionPipeline
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo"
11
 
12
  torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
13
 
14
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
15
  pipe = pipe.to(device)
16
 
 
 
 
 
17
  MAX_SEED = np.iinfo(np.int32).max
18
- MAX_IMAGE_SIZE = 1024
19
 
20
  # @spaces.GPU # Uncomment if using ZeroGPU
21
  def infer(
22
- environment,
23
  pose,
24
  negative_prompt,
25
  seed,
@@ -35,9 +39,12 @@ def infer(
35
 
36
  generator = torch.Generator().manual_seed(seed)
37
 
38
- # Construct prompt from dropdown selections
39
- prompt = f"A person {pose.lower()} in a {environment.lower()}, detailed, 8k"
40
 
 
 
 
41
  image = pipe(
42
  prompt=prompt,
43
  negative_prompt=negative_prompt,
@@ -59,19 +66,25 @@ css = """
59
 
60
  with gr.Blocks(css=css) as demo:
61
  with gr.Column(elem_id="col-container"):
62
- gr.Markdown(" # Text-to-Image Gradio with Controlled Prompt")
63
 
64
  with gr.Row():
65
- environment = gr.Dropdown(
66
- label="Environment",
67
- choices=["Jungle", "Desert", "Space Station", "Underwater", "Urban City"],
68
  value="Jungle",
69
  )
70
 
 
 
 
 
 
 
71
  pose = gr.Dropdown(
72
  label="Pose",
73
- choices=["Standing", "Sitting", "Running", "Flying", "Lying Down"],
74
- value="Standing",
75
  )
76
 
77
  run_button = gr.Button("Run", scale=0, variant="primary")
@@ -136,14 +149,14 @@ with gr.Blocks(css=css) as demo:
136
  ["Space Station", "Flying"],
137
  ["Urban City", "Sitting"],
138
  ],
139
- inputs=[environment, pose],
140
  )
141
 
142
  gr.on(
143
  triggers=[run_button.click],
144
  fn=infer,
145
  inputs=[
146
- environment,
147
  pose,
148
  negative_prompt,
149
  seed,
 
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ model_repo_id = "stabilityai/stable-diffusion-2-1-base"
11
 
12
  torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
13
 
14
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
15
  pipe = pipe.to(device)
16
 
17
+ backgrounds_list = ["forest", "city street", "beach", "office", "bus", "laboratory", "factory", "construction site", "hospital", "night club", ""]
18
+ poses_list = ["portrait", "side-portrait"]
19
+
20
+ gender_dict = {"ID_0": "male"}
21
  MAX_SEED = np.iinfo(np.int32).max
22
+ MAX_IMAGE_SIZE = 512
23
 
24
  # @spaces.GPU # Uncomment if using ZeroGPU
25
  def infer(
26
+ background,
27
  pose,
28
  negative_prompt,
29
  seed,
 
39
 
40
  generator = torch.Generator().manual_seed(seed)
41
 
42
+ id = "ID_0"
43
+ gender = gender_dict[id]
44
 
45
+ # Construct prompt from dropdown selections
46
+ prompt = f"face {pose.lower()} photo of {gender} {id} person, {background.lower()} background"
47
+ ""
48
  image = pipe(
49
  prompt=prompt,
50
  negative_prompt=negative_prompt,
 
66
 
67
  with gr.Blocks(css=css) as demo:
68
  with gr.Column(elem_id="col-container"):
69
+ gr.Markdown(" # ID-Booth Demo")
70
 
71
  with gr.Row():
72
+ which_id = gr.Dropdown(
73
+ label="Identity",
74
+ choices=backgrounds_list,
75
  value="Jungle",
76
  )
77
 
78
+ background = gr.Dropdown(
79
+ label="Background",
80
+ choices=backgrounds_list,
81
+ value=backgrounds_list[0],
82
+ )
83
+
84
  pose = gr.Dropdown(
85
  label="Pose",
86
+ choices=poses_list,
87
+ value="Portrait",
88
  )
89
 
90
  run_button = gr.Button("Run", scale=0, variant="primary")
 
149
  ["Space Station", "Flying"],
150
  ["Urban City", "Sitting"],
151
  ],
152
+ inputs=[background, pose],
153
  )
154
 
155
  gr.on(
156
  triggers=[run_button.click],
157
  fn=infer,
158
  inputs=[
159
+ background,
160
  pose,
161
  negative_prompt,
162
  seed,