gradio实用小技能汇总

gradio简介
  • gradio库是一个可以快速实现了一个机器学习或者深度学习模型的web端框架,该库已经集成到Hugging Face的Spaces中。
  • 只需要几行代码便可快速写出一个带有web界面的demo。
参数对应关系
# inference函数前几个参数分别一一对应下面的gr.Interface中inputs的几个参数
def inference(img, box_thresh, unclip_ratio, text_score):
    img_path = img.name
    img = cv2.imread(img_path)
    dt_boxes, rec_res = text_sys(img,
                                 box_thresh=box_thresh,
                                 unclip_ratio=unclip_ratio,
                                 text_score=text_score)
    img_save_path = visualize(img_path, dt_boxes, rec_res)
    return img_save_path, rec_res

gr.Interface(
    inference,
    inputs=[
        gr.inputs.Image(type='file', label='Input'),
        gr.Slider(minimum=0, maximum=1.0, value=0.5,
                  label='box_thresh', step=0.1),
        gr.Slider(minimum=1.5, maximum=2.0, value=1.6,
                  label='unclip_ratio', step=0.1),
        gr.Slider(minimum=0, maximum=1.0, value=0.5,
                  label='text_score', step=0.1),
    ],
    outputs=[
        gr.outputs.Image(type='file', label='Output_image'),
        gr.outputs.Textbox(type='text', label='Output_text')
    ],
    title=title,
    description=description,
    article=article,
    css=css,
    allow_flagging='never',
    ).launch(debug=True, enable_queue=True)
Slider的change用法
import gradio as gr

def update_value(val):
  return f'Value is set to {val}'

demo = gr.Blocks()

with demo:
  inp = gr.Slider(0, 100, label='Value')
  md = gr.Markdown('Select a value')

  inp.change(fn=update_value, inputs=inp, outputs=md)

demo.launch()
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值