Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -37,9 +37,11 @@ def inference(content_image, style_image, style_strength, output_quality, progre
|
|
37 |
|
38 |
print('CONTENT IMG SIZE:', original_size)
|
39 |
print('STYLE STRENGTH:', style_strength)
|
|
|
40 |
|
41 |
-
iters =
|
42 |
-
|
|
|
43 |
alpha = 1
|
44 |
beta = 1
|
45 |
|
@@ -47,7 +49,7 @@ def inference(content_image, style_image, style_strength, output_quality, progre
|
|
47 |
generated_img = content_img.clone().requires_grad_(True)
|
48 |
optimizer = optim.Adam([generated_img], lr=lr)
|
49 |
|
50 |
-
for
|
51 |
generated_features = model(generated_img)
|
52 |
content_features = model(content_img)
|
53 |
style_features = model(style_img)
|
@@ -91,7 +93,7 @@ with gr.Blocks(css=css) as demo:
|
|
91 |
gr.HTML("<h1 style='text-align: center; padding: 10px'>🖼️ Neural Style Transfer</h1>")
|
92 |
with gr.Column(elem_id='container'):
|
93 |
content_and_output = gr.Image(show_label=False, type='pil', sources=['upload'], format='jpg')
|
94 |
-
style_dropdown = gr.Radio(choices=list(style_options.keys()), label='
|
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)
|
@@ -100,7 +102,7 @@ with gr.Blocks(css=css) as demo:
|
|
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 |
with gr.Group():
|
103 |
-
output_quality = gr.Checkbox(label='
|
104 |
submit_button = gr.Button('Submit')
|
105 |
|
106 |
submit_button.click(fn=inference, inputs=[content_and_output, style_dropdown, style_strength_slider, output_quality], outputs=[content_and_output])
|
|
|
37 |
|
38 |
print('CONTENT IMG SIZE:', original_size)
|
39 |
print('STYLE STRENGTH:', style_strength)
|
40 |
+
print('HIGH QUALITY:', output_quality)
|
41 |
|
42 |
+
iters = 50
|
43 |
+
# learning rate determined by input
|
44 |
+
lr = 0.001 + (0.099 / 99) * (style_strength - 1)
|
45 |
alpha = 1
|
46 |
beta = 1
|
47 |
|
|
|
49 |
generated_img = content_img.clone().requires_grad_(True)
|
50 |
optimizer = optim.Adam([generated_img], lr=lr)
|
51 |
|
52 |
+
for iter in tqdm(range(iters), desc='The magic is happening ✨'):
|
53 |
generated_features = model(generated_img)
|
54 |
content_features = model(content_img)
|
55 |
style_features = model(style_img)
|
|
|
93 |
gr.HTML("<h1 style='text-align: center; padding: 10px'>🖼️ Neural Style Transfer</h1>")
|
94 |
with gr.Column(elem_id='container'):
|
95 |
content_and_output = gr.Image(show_label=False, type='pil', sources=['upload'], format='jpg')
|
96 |
+
style_dropdown = gr.Radio(choices=list(style_options.keys()), label='Style', value='Starry Night', type='value')
|
97 |
with gr.Accordion('Adjustments', open=False):
|
98 |
with gr.Group():
|
99 |
style_strength_slider = gr.Slider(label='Style Strength', minimum=1, maximum=100, step=1, value=50)
|
|
|
102 |
medium_button = gr.Button('Medium').click(fn=lambda: set_slider(50), outputs=[style_strength_slider])
|
103 |
high_button = gr.Button('High').click(fn=lambda: set_slider(100), outputs=[style_strength_slider])
|
104 |
with gr.Group():
|
105 |
+
output_quality = gr.Checkbox(label='More Realistic', info='Note: This takes longer, but improves output image quality')
|
106 |
submit_button = gr.Button('Submit')
|
107 |
|
108 |
submit_button.click(fn=inference, inputs=[content_and_output, style_dropdown, style_strength_slider, output_quality], outputs=[content_and_output])
|