赞
踩
使用参考gradio官方教程
gr.outputs
实现import gradio as gr import numpy as np def predict(prompt,image,is_rain): print('prompt',type(prompt)) print('image',type(image)) print('is_rain',type(is_rain)) image = np.fliplr(image) if prompt: output1 = prompt.upper() output2 = prompt.lower() else: output1=0 output2 = 0 return output1, output2, image outputs = [ gr.outputs.Textbox(label="Uppercase"), gr.outputs.Textbox(label="Lowercase"), gr.outputs.Image(type = 'numpy',label="Flipped Image") ] demo = gr.Interface( fn=predict, inputs=[ "text",'image','checkbox'], outputs=outputs, ) demo.launch()
输出
prompt <class 'str'>
image <class 'numpy.ndarray'>
is_rain <class 'bool'>
图片左边3个框是输入部分,显示的名字为传入参数的名字。右边的三个框是输出部分,名字是output中定义的label
launch(server_name="0.0.0.0")
,访问的时候将127.0.0.1
更换成运行设备的ipimport gradio as gr import numpy as np import gradio as gr import pandas as pd def display_table(image): data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'City': ['New York', 'London', 'Paris']} df = pd.DataFrame(data) return df # iface.launch() if __name__ == "__main__": # demo.launch() demo = gr.Interface(fn=display_table,inputs=['image'], outputs="dataframe") demo.launch(server_name="0.0.0.0") ## ip地址+端口号
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。