Spaces:
Runtime error
Runtime error
File size: 1,675 Bytes
6cde33e 63ec576 6cde33e e42b06e 6cde33e 90ba4b1 6cde33e 63ec576 6cde33e e42b06e 6cde33e e42b06e 5e9bf97 e42b06e 51ba501 6cde33e 5e9bf97 6cde33e e42b06e 51ba501 6cde33e |
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 |
import gradio as gr
import tensorflow as tf
import tensorflow_hub as hub
from PIL import Image
import numpy as np
model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
# Function to execute
def style_transfer(content_img, style_img):
content_img = tf.image.resize(tf.convert_to_tensor(content_img,tf.float32)[tf.newaxis,...] / 255.,(512,512),preserve_aspect_ratio=True)
style_img = tf.convert_to_tensor(style_img,tf.float32)[tf.newaxis,...] / 255.
generated_img = model(content_img, style_img)[0]
return Image.fromarray(np.uint8(generated_img[0]*255))
# Metadata
title = "Neural Style Transfer"
description = "Transform your photos into stunning works of art with our Neural Style Transfer app. Simply upload your content image and style image, and watch as the AI-powered model applies the artistic style of your choice to your photos. Unleash your creativity and turn ordinary images into extraordinary masterpieces!"
# Define labels for the input images
# input_labels = ["Content/Base Image", "Style Image"]
inputs = [
gr.Image(label="Content/Base Image"),
gr.Image(label="Style Image")
]
# Example images
examples = [
["content_example_1.jpg", "style_example_1.jpg"],
["content_example_2.jpg", "style_example_2.jpg"]
]
interface = gr.Interface(fn=style_transfer,
inputs=inputs,
outputs=["image"],
input_labels=input_labels,
title=title,
description=description,
examples=examples
)
interface.launch() |