[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)

相关推荐
该用户已成仙14 小时前
vue3 使用 vuedraggable 报错 TypeError: isFunction2 is not a function
前端·javascript·vue.js
TPBoreas14 小时前
前端面试问题打把-场景题
开发语言·前端·javascript
大鱼前端14 小时前
10 分钟用 Bun + Hono + SQLite 跑通一个全栈 API
前端·javascript
AC赳赳老秦14 小时前
OpenClaw + 华为云自动化:批量管理云资源、生成月度云账单分析与成本优化报告
java·开发语言·javascript·人工智能·python·mysql·openclaw
智码看视界15 小时前
Vue生态体系:构建现代化前端应用的完整解决方案
前端·javascript·vue.js
森叶15 小时前
Electron 多进程下的“库引入“全解析:核心模块、Electron API、第三方依赖与 utilityProcess 的依赖处理
运维·javascript·electron
小此方15 小时前
【别传:Web前端开发(三)】重塑动态视界:JS底层逻辑、数据类型流转与WebAPI交互全景草稿
前端·javascript·交互
仰望.15 小时前
vue表格使用 vxe-table 展开行实现产品列表与明细列表
前端·javascript·vue.js·vxe-table
meilindehuzi_a15 小时前
深入理解JavaScript线性数据结构:从内存视角探究数组、链表、栈与队列
javascript·数据结构·链表
Anastasiozzzz15 小时前
构建健壮软件系统的基石:深入解析面向对象设计七大原则
开发语言·javascript·设计模式·ecmascript