jamino30 commited on
Commit
632c209
·
verified ·
1 Parent(s): 396f6f7

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. StandingOnCliff-StarryNight.png +0 -0
  2. app.py +4 -9
  3. requirements.txt +2 -1
StandingOnCliff-StarryNight.png ADDED
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import time
2
  from PIL import Image
 
3
 
4
  import spaces
5
  import torch
@@ -85,7 +86,7 @@ style_options = {
85
  style_options = {k: f'./style_images/{v}' for k, v in style_options.items()}
86
 
87
  @spaces.GPU
88
- def inference(content_image, style_image):
89
  print('-'*15)
90
  print('STYLE:', style_image)
91
  img_size = 512
@@ -104,8 +105,7 @@ def inference(content_image, style_image):
104
  generated_img = content_img.clone().requires_grad_(True)
105
  optimizer = optim.Adam([generated_img], lr=lr)
106
 
107
- saved_image = None
108
- for iter in range(iters+1):
109
  generated_features = model(generated_img)
110
  content_features = model(content_img)
111
  style_features = model(style_img)
@@ -130,14 +130,10 @@ def inference(content_image, style_image):
130
  optimizer.zero_grad()
131
  total_loss.backward()
132
  optimizer.step()
133
-
134
- if iter % 15 == 0:
135
- saved_image = save_img(generated_img, original_size)
136
- yield (content_image, saved_image), f'{str(round(iter/iters*100))}% | {(time.time()-st):.2f}s'
137
 
138
  et = time.time()
139
  print('TIME TAKEN:', et-st)
140
- yield (content_image, save_img(generated_img, original_size)), f'{str(round(iter/iters*100))}% | {(et-st):.2f}s'
141
 
142
  css = """
143
  #style, #progress-label { height: 100px }
@@ -151,7 +147,6 @@ interface = gr.Interface(
151
  ],
152
  outputs=[
153
  ImageSlider(position=0.15, label='Output', show_download_button=True, interactive=False, elem_id='output'),
154
- gr.Label(label='Progress', elem_id='progress-label'),
155
  ],
156
  title="🖼️ Neural Style Transfer",
157
  api_name='style',
 
1
  import time
2
  from PIL import Image
3
+ from tqdm import tqdm
4
 
5
  import spaces
6
  import torch
 
86
  style_options = {k: f'./style_images/{v}' for k, v in style_options.items()}
87
 
88
  @spaces.GPU
89
+ def inference(content_image, style_image, progress=gr.Progress(track_tqdm=True)):
90
  print('-'*15)
91
  print('STYLE:', style_image)
92
  img_size = 512
 
105
  generated_img = content_img.clone().requires_grad_(True)
106
  optimizer = optim.Adam([generated_img], lr=lr)
107
 
108
+ for iter in tqdm(range(iters+1)):
 
109
  generated_features = model(generated_img)
110
  content_features = model(content_img)
111
  style_features = model(style_img)
 
130
  optimizer.zero_grad()
131
  total_loss.backward()
132
  optimizer.step()
 
 
 
 
133
 
134
  et = time.time()
135
  print('TIME TAKEN:', et-st)
136
+ return (content_image, save_img(generated_img, original_size))
137
 
138
  css = """
139
  #style, #progress-label { height: 100px }
 
147
  ],
148
  outputs=[
149
  ImageSlider(position=0.15, label='Output', show_download_button=True, interactive=False, elem_id='output'),
 
150
  ],
151
  title="🖼️ Neural Style Transfer",
152
  api_name='style',
requirements.txt CHANGED
@@ -4,4 +4,5 @@ torchvision
4
  pillow
5
  gradio
6
  gradio_imageslider
7
- spaces
 
 
4
  pillow
5
  gradio
6
  gradio_imageslider
7
+ spaces
8
+ tqdm