jamino30 commited on
Commit
01dd5e7
1 Parent(s): c311e63

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +6 -9
  2. vgg19.py +1 -1
app.py CHANGED
@@ -25,22 +25,21 @@ style_files = os.listdir('./style_images')
25
  style_options = {' '.join(style_file.split('.')[0].split('_')): f'./style_images/{style_file}' for style_file in style_files}
26
 
27
  @spaces.GPU(duration=35)
28
- def inference(content_image, style_image, style_strength, output_quality, progress=gr.Progress(track_tqdm=True)):
29
  yield None
30
  print('-'*15)
31
  print('DATETIME:', datetime.datetime.now())
32
  print('STYLE:', style_image)
33
- img_size = 1024 if output_quality else 512
34
  content_img, original_size = load_img(content_image, img_size)
35
  content_img = content_img.to(device)
36
  style_img = load_img_from_path(style_options[style_image], img_size)[0].to(device)
37
 
38
  print('CONTENT IMG SIZE:', original_size)
39
  print('STYLE STRENGTH:', style_strength)
40
- print('HIGH QUALITY:', output_quality)
41
 
42
  iters = style_strength
43
- lr = 1e-1
44
  alpha = 1
45
  beta = 1
46
 
@@ -95,16 +94,14 @@ with gr.Blocks(css=css) as demo:
95
  style_dropdown = gr.Radio(choices=list(style_options.keys()), label='Choose a style', value='Starry Night', type='value')
96
  with gr.Accordion('Adjustments', open=False):
97
  with gr.Group():
98
- style_strength_slider = gr.Slider(label='Style Strength', minimum=0, maximum=100, step=5, value=50)
99
  with gr.Row():
100
  low_button = gr.Button('Low').click(fn=lambda: set_slider(10), outputs=[style_strength_slider])
101
  medium_button = gr.Button('Medium').click(fn=lambda: set_slider(50), outputs=[style_strength_slider])
102
  high_button = gr.Button('High').click(fn=lambda: set_slider(100), outputs=[style_strength_slider])
103
- with gr.Group():
104
- output_quality = gr.Checkbox(label='High Quality', info='Note: This takes longer, but improves output image quality')
105
  submit_button = gr.Button('Submit')
106
 
107
- submit_button.click(fn=inference, inputs=[content_and_output, style_dropdown, style_strength_slider, output_quality], outputs=[content_and_output])
108
 
109
  examples = gr.Examples(
110
  examples=[
@@ -112,7 +109,7 @@ with gr.Blocks(css=css) as demo:
112
  ['./content_images/GoldenRetriever.jpg', 'Lego Bricks', 50, False],
113
  ['./content_images/SeaTurtle.jpg', 'Mosaic', 100, False]
114
  ],
115
- inputs=[content_and_output, style_dropdown, style_strength_slider, output_quality]
116
  )
117
 
118
  # disable queue
 
25
  style_options = {' '.join(style_file.split('.')[0].split('_')): f'./style_images/{style_file}' for style_file in style_files}
26
 
27
  @spaces.GPU(duration=35)
28
+ def inference(content_image, style_image, style_strength, progress=gr.Progress(track_tqdm=True)):
29
  yield None
30
  print('-'*15)
31
  print('DATETIME:', datetime.datetime.now())
32
  print('STYLE:', style_image)
33
+ img_size = 512
34
  content_img, original_size = load_img(content_image, img_size)
35
  content_img = content_img.to(device)
36
  style_img = load_img_from_path(style_options[style_image], img_size)[0].to(device)
37
 
38
  print('CONTENT IMG SIZE:', original_size)
39
  print('STYLE STRENGTH:', style_strength)
 
40
 
41
  iters = style_strength
42
+ lr = 5e-2
43
  alpha = 1
44
  beta = 1
45
 
 
94
  style_dropdown = gr.Radio(choices=list(style_options.keys()), label='Choose a style', value='Starry Night', type='value')
95
  with gr.Accordion('Adjustments', open=False):
96
  with gr.Group():
97
+ style_strength_slider = gr.Slider(label='Style Strength', minimum=1, maximum=100, step=1, value=50)
98
  with gr.Row():
99
  low_button = gr.Button('Low').click(fn=lambda: set_slider(10), outputs=[style_strength_slider])
100
  medium_button = gr.Button('Medium').click(fn=lambda: set_slider(50), outputs=[style_strength_slider])
101
  high_button = gr.Button('High').click(fn=lambda: set_slider(100), outputs=[style_strength_slider])
 
 
102
  submit_button = gr.Button('Submit')
103
 
104
+ submit_button.click(fn=inference, inputs=[content_and_output, style_dropdown, style_strength_slider], outputs=[content_and_output])
105
 
106
  examples = gr.Examples(
107
  examples=[
 
109
  ['./content_images/GoldenRetriever.jpg', 'Lego Bricks', 50, False],
110
  ['./content_images/SeaTurtle.jpg', 'Mosaic', 100, False]
111
  ],
112
+ inputs=[content_and_output, style_dropdown, style_strength_slider]
113
  )
114
 
115
  # disable queue
vgg19.py CHANGED
@@ -4,7 +4,7 @@ import torchvision.models as models
4
  class VGG_19(nn.Module):
5
  def __init__(self):
6
  super(VGG_19, self).__init__()
7
- self.model = models.vgg19(pretrained=True).features[:30]
8
 
9
  for i, _ in enumerate(self.model):
10
  if i in [4, 9, 18, 27]:
 
4
  class VGG_19(nn.Module):
5
  def __init__(self):
6
  super(VGG_19, self).__init__()
7
+ self.model = models.vgg19(weights='DEFAULT').features[:30]
8
 
9
  for i, _ in enumerate(self.model):
10
  if i in [4, 9, 18, 27]: