[Bug]使用gradio创建应用提示AttributeError: module ‘gradio‘ has no attribute ‘inputs‘

源代码

import gradio as gr

gr.Interface(fn=predict,

inputs=gr.inputs.Image(shape=(512, 512)),

outputs=gr.outputs.Label(num_top_classes=3)

).launch(share=True)

错误

复制代码
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[7], line 4
      1 import gradio as gr
      3 gr.Interface(fn=predict, 
----> 4              inputs=gr.inputs.Image(shape=(512, 512)), 
      5              outputs=gr.outputs.Label(num_top_classes=3)
      6             ).launch(share=True)

AttributeError: module 'gradio' has no attribute 'inputs'

原因

我安装的gradio是最新版本:4.36.1

但是这个是老的API,只支持到3.41.0

解决办法

1.重新安装老的

pip install gradio==3.41.0

2.用新的API,代码例子如下:

import gradio as gr

gr.Interface(fn=predict,

inputs=gr.Image(),

outputs=gr.Label(num_top_classes=3)

).launch(share=True)

相关推荐
接着奏乐接着舞12 小时前
react useMeno useCallback
前端·javascript·react.js
码农阿豪12 小时前
Vue项目构建中ESLint的“换行符战争”:从报错到优雅解决
前端·javascript·vue.js
韩曙亮13 小时前
【Web APIs】BOM 浏览器对象模型 ⑥ ( location 对象 | location 常用属性和方法 | URL 简介 )
前端·javascript·dom·url·bom·location·浏览器对象模型
春生野草14 小时前
Ruoyi前端基于vue的脚手架的目录解析
前端·javascript·vue.js
m0_7400437314 小时前
Axios拦截器 -- 请求拦截器和响应拦截器
开发语言·前端·javascript
风止何安啊15 小时前
递归 VS 动态规划:从 “无限套娃计算器” 到 “积木式解题神器”
前端·javascript·算法
GPTMirrors镜像系统15 小时前
JS 实现指定 UA 访问网站跳转弹窗提醒,解决夸克等浏览器兼容性问题
前端·javascript
脾气有点小暴15 小时前
JavaScript 数据存储方法全解析:从基础到进阶
开发语言·javascript·ecmascript
BD_Marathon15 小时前
【JavaWeb】JS_JSON和Map_List_array之间的转换
javascript
Rysxt_15 小时前
Vue文件下载功能完整指南:从基础实现到进阶实战
前端·javascript·vue.js