Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ from datetime import datetime, timezone, timedelta
|
|
4 |
|
5 |
import spaces
|
6 |
import torch
|
|
|
7 |
import gradio as gr
|
8 |
|
9 |
from utils import preprocess_img, preprocess_img_from_path, postprocess_img
|
@@ -31,8 +32,10 @@ for style_name, style_img_path in style_options.items():
|
|
31 |
style_features = (model(style_img_512), model(style_img_1024))
|
32 |
cached_style_features[style_name] = style_features
|
33 |
|
|
|
|
|
34 |
@spaces.GPU(duration=15)
|
35 |
-
def run(content_image, style_name, style_strength=
|
36 |
yield None
|
37 |
img_size = 1024 if output_quality else 512
|
38 |
content_img, original_size = preprocess_img(content_image, img_size)
|
@@ -46,14 +49,13 @@ def run(content_image, style_name, style_strength=100, output_quality=False, pro
|
|
46 |
print('HIGH QUALITY:', output_quality)
|
47 |
|
48 |
style_features = cached_style_features[style_name][0 if img_size == 512 else 1]
|
49 |
-
converted_lr = 0.001 + (0.009 / 99) * (style_strength - 1) # [0.001, 0.01]
|
50 |
|
51 |
st = time.time()
|
52 |
generated_img = inference(
|
53 |
model=model,
|
54 |
content_image=content_img,
|
55 |
style_features=style_features,
|
56 |
-
lr=
|
57 |
)
|
58 |
et = time.time()
|
59 |
print('TIME TAKEN:', et-st)
|
@@ -78,7 +80,7 @@ with gr.Blocks(css=css) as demo:
|
|
78 |
style_dropdown = gr.Radio(choices=list(style_options.keys()), label='Style', value='Starry Night', type='value')
|
79 |
|
80 |
with gr.Group():
|
81 |
-
style_strength_slider = gr.Slider(label='Style Strength', minimum=1, maximum=
|
82 |
with gr.Row():
|
83 |
low_button = gr.Button('Low', size='sm').click(fn=lambda: set_slider(10), outputs=[style_strength_slider])
|
84 |
medium_button = gr.Button('Medium', size='sm').click(fn=lambda: set_slider(50), outputs=[style_strength_slider])
|
|
|
4 |
|
5 |
import spaces
|
6 |
import torch
|
7 |
+
import numpy as np
|
8 |
import gradio as gr
|
9 |
|
10 |
from utils import preprocess_img, preprocess_img_from_path, postprocess_img
|
|
|
32 |
style_features = (model(style_img_512), model(style_img_1024))
|
33 |
cached_style_features[style_name] = style_features
|
34 |
|
35 |
+
lrs = np.logspace(np.log10(0.001), np.log10(0.1), 10).tolist()
|
36 |
+
|
37 |
@spaces.GPU(duration=15)
|
38 |
+
def run(content_image, style_name, style_strength=5, output_quality=False, progress=gr.Progress(track_tqdm=True)):
|
39 |
yield None
|
40 |
img_size = 1024 if output_quality else 512
|
41 |
content_img, original_size = preprocess_img(content_image, img_size)
|
|
|
49 |
print('HIGH QUALITY:', output_quality)
|
50 |
|
51 |
style_features = cached_style_features[style_name][0 if img_size == 512 else 1]
|
|
|
52 |
|
53 |
st = time.time()
|
54 |
generated_img = inference(
|
55 |
model=model,
|
56 |
content_image=content_img,
|
57 |
style_features=style_features,
|
58 |
+
lr=lrs[style_strength-1]
|
59 |
)
|
60 |
et = time.time()
|
61 |
print('TIME TAKEN:', et-st)
|
|
|
80 |
style_dropdown = gr.Radio(choices=list(style_options.keys()), label='Style', value='Starry Night', type='value')
|
81 |
|
82 |
with gr.Group():
|
83 |
+
style_strength_slider = gr.Slider(label='Style Strength', minimum=1, maximum=10, step=1, value=5)
|
84 |
with gr.Row():
|
85 |
low_button = gr.Button('Low', size='sm').click(fn=lambda: set_slider(10), outputs=[style_strength_slider])
|
86 |
medium_button = gr.Button('Medium', size='sm').click(fn=lambda: set_slider(50), outputs=[style_strength_slider])
|