Downloads · 30 days
0
basceng123/Waw
Waw is a machine learning model from basceng123. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
import gradio as gr import numpy as np from PIL import Image, ImageDraw
Downloads · 30 days
0
Access
Public
Updated Dec 21, 2023
Repo size
—
Likes
0
Public
Click a slice to open those files.
Other1.5 KB · 57%
From the Hugging Face model README
import gradio as gr import numpy as np from PIL import Image, ImageDraw
def generate_mask(image, mask_points): # 创建一个与原始图像相同大小的空白图像 mask = Image.new('L', image.size, 0) draw = ImageDraw.Draw(mask)
# 绘制多边形蒙版
draw.polygon(mask_points, fill=255)
# 将蒙版应用到原始图像
masked_image = Image.new('RGBA', image.size)
masked_image.paste(image, (0, 0), mask)
return masked_image
def generate_masked_image(image, mask_points): masked_image = generate_mask(image, mask_points) return masked_image
def generate_downloadable_image(image, mask_points): masked_image = generate_mask(image, mask_points) return masked_image
def image_to_array(image): return np.array(image)
def array_to_image(array): return Image.fromarray(np.uint8(array))
iface = gr.Interface( fn=generate_masked_image, inputs=[ gr.inputs.Image(label="原始图像"), gr.inputs.ImageDraw(label="绘制蒙版", drawing_mode="freedraw", outputs="points") ], outputs=gr.outputs.Image(label="蒙版图像") )
iface.launch()