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

相关推荐
Dxy123931021620 小时前
JavaScript 字符串转数值(小数)
开发语言·javascript·ecmascript
黑夜里的小夜莺21 小时前
黑马点评登录成功后点击【我的】会跳转到登录页面 BUG 修复
java·bug
lightqjx21 小时前
【前端】前端学习三之初识JavaScript
前端·javascript·学习
晓得迷路了21 小时前
栗子前端技术周刊第 127 期 - pnpm 11.0、Remix 3 Beta Preview、Astro 6.20...
前端·javascript·css
ZC跨境爬虫1 天前
跟着 MDN 学 HTML day_16:(音频与视频处理——从画布滤镜到3D沉浸音频的进阶指南)
前端·javascript·ui·3d·html·音视频
天若有情6731 天前
程序员原创|借鉴JS事件冒泡,根治电脑文件混乱的“冒泡整理法”
开发语言·javascript·windows·ecmascript·电脑·办公·日常
FYKJ_20101 天前
springboot校园兼职平台--附源码02041
java·javascript·spring boot·python·eclipse·django·php
熟人看不到1 天前
解决Claude Code界面错位更新不及时-Windows
bug·vibecoding·claude code
深念Y2 天前
踩坑实录:把 Windows 默认 PowerShell 换成 7.x 到底有多坑?一条龙解决指南
windows·乱码·bug·控制台·powershell·管道·流式
空中海2 天前
01 React Native 基础、核心组件与布局体系
javascript·react native·react.js