Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import torch.optim as optim
|
|
9 |
import torchvision.transforms as transforms
|
10 |
import torchvision.models as models
|
11 |
import gradio as gr
|
|
|
12 |
|
13 |
if torch.cuda.is_available(): device = 'cuda'
|
14 |
elif torch.backends.mps.is_available(): device = 'mps'
|
@@ -82,8 +83,7 @@ style_options = {
|
|
82 |
# styles
|
83 |
'Lego Bricks': 'LegoBricks.jpg',
|
84 |
'Oil Painting': 'OilPainting.jpg',
|
85 |
-
'Mosaic': 'Mosaic.jpg'
|
86 |
-
'8Bit': '8Bit.jpg',
|
87 |
}
|
88 |
style_options = {k: f'./style_images/{v}' for k, v in style_options.items()}
|
89 |
|
@@ -140,33 +140,37 @@ def inference(content_image, style_image, style_strength, progress=gr.Progress(t
|
|
140 |
|
141 |
def set_slider(value):
|
142 |
return gr.update(value=value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
low_button = gr.Button('Low').click(fn=lambda: set_slider(10), outputs=[style_strength_slider])
|
155 |
-
medium_button = gr.Button('Medium').click(fn=lambda: set_slider(50), outputs=[style_strength_slider])
|
156 |
-
high_button = gr.Button('High').click(fn=lambda: set_slider(100), outputs=[style_strength_slider])
|
157 |
-
submit_button = gr.Button('Submit')
|
158 |
-
with gr.Column():
|
159 |
-
output_image = gr.Image(label='Output', show_download_button=True, interactive=False)
|
160 |
-
|
161 |
-
submit_button.click(fn=inference, inputs=[content_image, style_dropdown, style_strength_slider], outputs=[output_image])
|
162 |
-
|
163 |
-
examples = gr.Examples(
|
164 |
-
examples=[
|
165 |
-
['./content_images/TajMahal.jpg', 'Starry Night', 75],
|
166 |
-
['./content_images/GoldenRetriever.jpg', 'Lego Bricks', 50],
|
167 |
-
['./content_images/SeaTurtle.jpg', 'Mosaic', 100]
|
168 |
-
],
|
169 |
-
inputs=[content_image, style_dropdown, style_strength_slider]
|
170 |
-
)
|
171 |
|
172 |
demo.launch(show_api=True)
|
|
|
9 |
import torchvision.transforms as transforms
|
10 |
import torchvision.models as models
|
11 |
import gradio as gr
|
12 |
+
from gradio_imageslider import ImageSlider
|
13 |
|
14 |
if torch.cuda.is_available(): device = 'cuda'
|
15 |
elif torch.backends.mps.is_available(): device = 'mps'
|
|
|
83 |
# styles
|
84 |
'Lego Bricks': 'LegoBricks.jpg',
|
85 |
'Oil Painting': 'OilPainting.jpg',
|
86 |
+
'Mosaic': 'Mosaic.jpg'
|
|
|
87 |
}
|
88 |
style_options = {k: f'./style_images/{v}' for k, v in style_options.items()}
|
89 |
|
|
|
140 |
|
141 |
def set_slider(value):
|
142 |
return gr.update(value=value)
|
143 |
+
|
144 |
+
css = """
|
145 |
+
#container {
|
146 |
+
margin: 0 auto;
|
147 |
+
max-width: 550px;
|
148 |
+
}
|
149 |
+
"""
|
150 |
+
|
151 |
+
with gr.Blocks(css=css) as demo:
|
152 |
+
gr.HTML("<h1 style='text-align: center; padding: 10px'>🖼️ Neural Style Transfer</h1>")
|
153 |
+
with gr.Column(elem_id='container'):
|
154 |
+
content_and_output = gr.Image(show_label=False, type='pil', sources=['upload'])
|
155 |
+
style_dropdown = gr.Radio(choices=list(style_options.keys()), label='Choose a style', value='Starry Night', type='value')
|
156 |
+
with gr.Accordion('Adjustments', open=False):
|
157 |
+
with gr.Group():
|
158 |
+
style_strength_slider = gr.Slider(label='Style Strength', minimum=0, maximum=100, step=5, value=50)
|
159 |
+
with gr.Row():
|
160 |
+
low_button = gr.Button('Low').click(fn=lambda: set_slider(10), outputs=[style_strength_slider])
|
161 |
+
medium_button = gr.Button('Medium').click(fn=lambda: set_slider(50), outputs=[style_strength_slider])
|
162 |
+
high_button = gr.Button('High').click(fn=lambda: set_slider(100), outputs=[style_strength_slider])
|
163 |
+
submit_button = gr.Button('Submit')
|
164 |
|
165 |
+
submit_button.click(fn=inference, inputs=[content_and_output, style_dropdown, style_strength_slider], outputs=[content_and_output])
|
166 |
+
|
167 |
+
examples = gr.Examples(
|
168 |
+
examples=[
|
169 |
+
['./content_images/TajMahal.jpg', 'Starry Night', 75],
|
170 |
+
['./content_images/GoldenRetriever.jpg', 'Lego Bricks', 50],
|
171 |
+
['./content_images/SeaTurtle.jpg', 'Mosaic', 100]
|
172 |
+
],
|
173 |
+
inputs=[content_and_output, style_dropdown, style_strength_slider]
|
174 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
demo.launch(show_api=True)
|