Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3605313
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2022-12-28 16:31:42

import gradio as gr

from modelscope.pipelines import pipeline

from modelscope.utils.constant import Tasks

from modelscope.utils.cv.image_utils import draw_face_detection_no_lm_result

from modelscope.preprocessors.image import LoadImage

from PIL import Image

import cv2

import numpy as np

###########################################

# gradio demo app 推断入口

###########################################

# gradio app demo 算法运行函数

def inference(input_file):

    mog_face_detection_func = pipeline(Tasks.face_detection, 'damo/cv_resnet101_face-detection_cvpr22papermogface')

    src_img_path = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/mog_face_detection.jpg'

    raw_result = mog_face_detection_func(src_img_path)

    print('face detection output: {}.'.format(raw_result))

    # load image from url as rgb order

    src_img = LoadImage.convert_to_ndarray(src_img_path)

    # save src image as bgr order to local

    src_img  = cv2.cvtColor(np.asarray(src_img), cv2.COLOR_RGB2BGR)

    cv2.imwrite('src_img.jpg', src_img)

    # draw dst image from local src image as bgr order

    dst_img = draw_face_detection_no_lm_result('src_img.jpg', raw_result)

    # convert to rgb order

    dst_img  = cv2.cvtColor(np.asarray(dst_img), cv2.COLOR_BGR2RGB)

    return dst_img

# gradio app 环境参数

css_style = "#fixed_size_img {height: 240px;} " \

            "#overview {margin: auto;max-width: 600px; max-height: 400px;}"

title = "AI人脸检测应用"

###########################################

# gradio demo app

###########################################

with gr.Blocks(title=title, css=css_style) as demo:

    gr.HTML('''

      

                  

                    style="

                      display: inline-flex;

                      align-items: center;

                      gap: 0.8rem;

                      font-size: 1.75rem;

                    "

                  >

                    

                      AI人脸检测应用

                    

      ''')

    with gr.Row():

        img_input = gr.Image(type="pil", elem_id="fixed_size_img")

        img_output = gr.Image(type="pil", elem_id="fixed_size_img")

    with gr.Row():

        btn_submit = gr.Button(value="一键生成", elem_id="blue_btn")

    examples =跟单网gendan5.com [['https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/mog_face_detection.jpg']]

    examples = gr.Examples(examples=examples, inputs=img_input, outputs=img_output, label="点击如下示例试玩", run_on_click=True)

    btn_submit.click(inference, inputs=[img_input], outputs=img_output)

    # btn_clear清除画布

if __name__ == "__main__":

    demo.launch(share=True)

阅读(546) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~