shaoan xie commited on
Commit
048f364
1 Parent(s): 994b813

requirements2

Browse files
Files changed (2) hide show
  1. app.py +20 -22
  2. requirements.txt +1 -1
app.py CHANGED
@@ -5,11 +5,8 @@ from torchvision.utils import save_image
5
  import numpy as np
6
  from diffusers import StableDiffusionUpscalePipeline
7
  from huggingface_hub import hf_hub_download
8
- import torch
9
-
10
- # Load the model from Hugging Face Hub
11
- model_path = hf_hub_download(repo_id="Shaoan/ConceptGAN", filename="augceleba_6451.pkl")
12
 
 
13
  with open(model_path, 'rb') as f:
14
  G = pickle.load(f)['G_ema'].cpu().float() # torch.nn.Module
15
 
@@ -138,30 +135,29 @@ def generate(seed, upscale, upscale_steps,*checkboxes):
138
  # Create the interface using gr.Blocks
139
  with gr.Blocks() as demo:
140
  with gr.Row():
141
- sliders = [
142
- gr.Slider(label='Bald', minimum=0, maximum=1, step=0.01),
143
- gr.Slider(label='Black Hair', minimum=0, maximum=1, step=0.01),
144
- gr.Slider(label='Blond Hair', minimum=0, maximum=1, step=0.01),
145
- gr.Slider(label='Straight Hair', minimum=0, maximum=1, step=0.01),
146
- gr.Slider(label='Wavy Hair', minimum=0, maximum=1, step=0.01),
147
- ]
148
 
149
  with gr.Row():
150
- sliders += [gr.Slider(label='Young', minimum=0, maximum=1, step=0.01)]
151
- sliders += [gr.Slider(label='Male', minimum=0, maximum=1, step=0.01)]
152
 
153
  with gr.Row():
154
- sliders += [gr.Slider(label='Goatee', minimum=0, maximum=1, step=0.01)]
155
- sliders += [gr.Slider(label='Mustache', minimum=0, maximum=1, step=0.01)]
156
 
157
  with gr.Row():
158
  sliders += [
159
- gr.Slider(label='Big Nose', minimum=0, maximum=1, step=0.01),
160
- gr.Slider(label='Chubby', minimum=0, maximum=1, step=0.01),
161
- gr.Slider(label='Eyeglasses', minimum=0, maximum=1, step=0.01),
162
- gr.Slider(label='Pale Skin', minimum=0, maximum=1, step=0.01),
163
- gr.Slider(label='Smiling', minimum=0, maximum=1, step=0.01),
164
- gr.Slider(label='Wearing Hat', minimum=0, maximum=1, step=0.01),
165
  ]
166
 
167
  seed_input = gr.Number(label="Seed", value=6)
@@ -172,9 +168,11 @@ with gr.Blocks() as demo:
172
  generate_button = gr.Button("Generate")
173
 
174
  output_image = gr.Image(label="Generated Image")
 
 
175
 
176
  # Set the action for the button
177
  generate_button.click(fn=generate, inputs=[seed_input] + upscale_funcs +sliders, outputs=output_image)
178
 
179
  # Launch the demo
180
- demo.launch()
 
5
  import numpy as np
6
  from diffusers import StableDiffusionUpscalePipeline
7
  from huggingface_hub import hf_hub_download
 
 
 
 
8
 
9
+ model_path = hf_hub_download(repo_id="Shaoan/ConceptGAN", filename="augceleba_8064.pkl")
10
  with open(model_path, 'rb') as f:
11
  G = pickle.load(f)['G_ema'].cpu().float() # torch.nn.Module
12
 
 
135
  # Create the interface using gr.Blocks
136
  with gr.Blocks() as demo:
137
  with gr.Row():
138
+ slider1 = gr.Slider(label='Not Bald <--------------> Bald', minimum=0, maximum=1, step=0.01)
139
+ slider2 = gr.Slider(label='No Black Hair <--------> Black Hair', minimum=0, maximum=1, step=0.01)
140
+ slider3 = gr.Slider(label='No Blond Hair <--------> Blond Hair', minimum=0, maximum=1, step=0.01)
141
+ slider4 = gr.Slider(label='No Straight Hair <-----> Straight Hair', minimum=0, maximum=1, step=0.01)
142
+ slider5 = gr.Slider(label='No Wavy Hair <-------> Wavy Hair', minimum=0, maximum=1, step=0.01)
143
+ sliders = [ slider1, slider2, slider3, slider4, slider5]
 
144
 
145
  with gr.Row():
146
+ sliders += [gr.Slider(label='Old <--------------> Young', minimum=0, maximum=1, step=0.01)]
147
+ sliders += [gr.Slider(label='Female <--------------> Male', minimum=0, maximum=1, step=0.01)]
148
 
149
  with gr.Row():
150
+ sliders += [gr.Slider(label='No Goatee <--------------> Goatee', minimum=0, maximum=1, step=0.01)]
151
+ sliders += [gr.Slider(label='No Mustache <--------------> Mustache', minimum=0, maximum=1, step=0.01)]
152
 
153
  with gr.Row():
154
  sliders += [
155
+ gr.Slider(label='Small Nose <-------> Big Nose', minimum=0, maximum=1, step=0.01),
156
+ gr.Slider(label='Slim <--------> Chubby', minimum=0, maximum=1, step=0.01),
157
+ gr.Slider(label='No Eyeglasses <--------> Eyeglasses', minimum=0, maximum=1, step=0.01),
158
+ gr.Slider(label='Tan Skin <-------> Pale Skin', minimum=0, maximum=1, step=0.01),
159
+ gr.Slider(label='Not Smiling <---------> Smiling', minimum=0, maximum=1, step=0.01),
160
+ gr.Slider(label='No Hat <---------> Wearing Hat', minimum=0, maximum=1, step=0.01),
161
  ]
162
 
163
  seed_input = gr.Number(label="Seed", value=6)
 
168
  generate_button = gr.Button("Generate")
169
 
170
  output_image = gr.Image(label="Generated Image")
171
+ for slider in sliders:
172
+ slider.change(fn=generate, inputs=[seed_input] + upscale_funcs + sliders, outputs=output_image)
173
 
174
  # Set the action for the button
175
  generate_button.click(fn=generate, inputs=[seed_input] + upscale_funcs +sliders, outputs=output_image)
176
 
177
  # Launch the demo
178
+ demo.launch()
requirements.txt CHANGED
@@ -8,5 +8,5 @@ psutil~=6.0.0
8
  gradio==4.36.1
9
  diffusers==0.20.0
10
  huggingface_hub==0.24.6
11
- transformers==4.19.2
12
  accelerate
 
8
  gradio==4.36.1
9
  diffusers==0.20.0
10
  huggingface_hub==0.24.6
11
+ transformers==4.31.0
12
  accelerate