Spaces:
Sleeping
Sleeping
File size: 2,090 Bytes
2454319 3b9ffab 2454319 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import gradio as gr
from style_transfer import StyleTransfer
style = StyleTransfer()
def predict(content_image, style_image):
return style.transfer(content_image, style_image)
footer = r"""
<center>
<b>
Demo for <a href='https://www.tensorflow.org/hub/tutorials/tf2_arbitrary_image_stylization'>Style Transfer</a>
</b>
</center>
"""
coffe = r"""
<center>
<a href="https://www.buymeacoffee.com/leonelhs"> <img
src="https://img.buymeacoffee.com/button-api/?text=Buy me a
coffee&emoji=&slug=leonelhs&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000
&coffee_colour=ffffff" /></a>
</center>
"""
with gr.Blocks(title="Style Transfer") as app:
gr.HTML("<center><h1>Style Transfer</h1></center>")
gr.HTML("<center><h3>Fast Style Transfer for Arbitrary Styles</h3></center>")
with gr.Row(equal_height=False):
with gr.Column():
with gr.Row(equal_height=True):
with gr.Column():
content_img = gr.Image(type="filepath", label="Content image")
with gr.Column():
style_img = gr.Image(type="filepath", label="Style image")
run_btn = gr.Button(variant="primary")
with gr.Column():
output_img = gr.Image(type="pil", label="Output image")
gr.ClearButton(components=[content_img, style_img, output_img], variant="stop")
run_btn.click(predict, [content_img, style_img], [output_img])
with gr.Row():
blobs_c = [[f"examples/contents/{x:02d}.jpg"] for x in range(1, 4)]
examples_c = gr.Dataset(components=[content_img], samples=blobs_c)
examples_c.click(lambda x: x[0], [examples_c], [content_img])
with gr.Row():
blobs_s = [[f"examples/styles/{x:02d}.jpg"] for x in range(1, 12)]
examples_s = gr.Dataset(components=[style_img], samples=blobs_s)
examples_s.click(lambda x: x[0], [examples_s], [style_img])
with gr.Row():
gr.HTML(footer)
with gr.Row():
gr.HTML(coffe)
app.launch(share=False, debug=True, show_error=True)
app.queue()
|