File size: 2,008 Bytes
9c27f4d
a2f6548
 
9c27f4d
0987ddf
a2f6548
266e51e
a2f6548
f8c2103
 
c47f1f2
a2f6548
 
 
 
 
76997e6
a2f6548
 
7c3ffce
76997e6
a2f6548
73ff91d
 
 
5c7d104
9c27f4d
bdf746e
 
 
 
 
 
 
 
 
 
0987ddf
73ff91d
0987ddf
9c27f4d
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
import gradio as gr
from PIL import Image, ImageDraw, ImageFont
import io


# 定义一个函数,它接受一张图片和一些文本,返回一个 HTML 页面
def create_html_page(input_image):
    # 将输入图片转换为 Pillow Image 对象
    image = Image.open(input_image)
    # image = input_image
    # print(image.shape)
    # 创建一个新的 Pillow Image 对象,大小为原始图片大小加上文本高度
    new_image = Image.new('RGB', (image.width, image.height + 50), color = 'white')
    new_image.paste(image, (0, 0))
    draw = ImageDraw.Draw(new_image)
    # 定义字体、字号和颜色
    # font = ImageFont.truetype("arial.ttf", 36)
    color = (0, 0, 0)
    # 在图片下方绘制文本
    text = 'model output text'
    draw.text((0, image.height), text, fill=color)
    # 将带有图片和文本的 HTML 页面返回
    # output_html = '<img src="data:image/png;base64,{}">'.format(
    #     draw.getvalue().encode('base64').decode())
    # output_html += '<p>{}</p>'.format(text)
    return image

# Create Gradio input and output components
image_input = gr.inputs.Image(type='filepath', label="Input Image")
image_caption_checkbox = gr.inputs.Checkbox(label="Image Caption", default=True)
dense_caption_checkbox = gr.inputs.Checkbox(label="Dense Caption", default=True)
semantic_segment_checkbox = gr.inputs.Checkbox(label="Semantic Segment", default=False)
image_caption_device = gr.inputs.Radio(choices=['cuda', 'cpu'], default='cpu', label='Image Caption Device')
dense_caption_device = gr.inputs.Radio(choices=['cuda', 'cpu'], default='cuda', label='Dense Caption Device')
semantic_segment_device = gr.inputs.Radio(choices=['cuda', 'cpu'], default='cuda', label='Semantic Segment Device')
controlnet_device = gr.inputs.Radio(choices=['cuda', 'cpu'], default='cpu', label='ControlNet Device')

# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface = gr.Interface(fn=create_html_page, inputs=[image_input], outputs=["image"])

iface.launch()