gradio简介
gradio库是一个可以快速实现了一个机器学习或者深度学习模型的web端框架,该库已经集成到Hugging Face的Spaces中。 只需要几行代码便可快速写出一个带有web界面的demo。
参数对应关系
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 )
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( )