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

相关推荐
To_OC13 小时前
LC 131 分割回文串:刚学回溯时,我连怎么切字符串都想不明白
javascript·算法·leetcode
To_OC14 小时前
LC 42 接雨水:暴力超时卡半天?前后缀数组一用就通了
javascript·算法·leetcode
小林ixn14 小时前
从 ??= 到 onKeyDown:一个 React 组件的“自我修养”
前端·javascript·react.js
এ慕ོ冬℘゜15 小时前
前端实战:jQuery 多条件联合搜索(标题模糊查询 + 日历时间段筛选)
前端·javascript·jquery
随心点儿16 小时前
js postMessage 实现跨域发送消息-应用示例
javascript·ecmascript·postmessage
kyriewen17 小时前
我让AI改一个bug——它偷偷动了5个我没让它碰的地方
前端·javascript·ai编程
gis开发之家1 天前
《Vue3 从入门到大神35篇》Vue3 源码详解(五):effect 依赖收集原理——track 与 trigger 是如何工作的?
javascript·typescript·前端框架·vue3·vue3源码
橘子星1 天前
我一个前端切图仔,凭什么能在浏览器里跑大模型?
前端·javascript·前端框架
半个落月1 天前
用 LangChain JS 做可控写作实验:理解温度参数、提示词与异步调用
javascript·人工智能·后端
观远数据1 天前
Excel到数据资产池:文件数据入湖的治理规范怎么建
前端·javascript·excel