安装
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install paddlepaddle==2.5.2
pip3 install --upgrade paddlehub
pip3 install gradio
代码
import gradio as gr
import paddlehub as hub
import cv2
def fn(pic,style):
stylepro_artistic = hub.Module(name="stylepro_artistic")
# 读入图片并开始风格转换
result = stylepro_artistic.style_transfer(
images=[{'content': cv2.imread(pic),
'styles': [cv2.imread(style)]}],
visualization=True)
return result[0]['save_path']
with gr.Blocks(title="Style Transfer") as demo:
gr.Markdown("# Style Transfer")
gr.Interface(fn, [gr.Image(type = "filepath"),gr.Image(type = "filepath")], "image")
demo.launch(server_name="0.0.0.0", server_port=3456)
运行效果