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

相关推荐
程序员大阳36 分钟前
副队长JavaScript教程(67)-Ajax初识:背景、历史与核心概念
javascript·ajax·同步·异步·概念·背景·来是
程序员大阳40 分钟前
副队长JavaScript教程(70)-Ajax同源策略与跨域
javascript·ajax·同源策略·跨越·corp
普通人61 小时前
Web端3D模型加载实战指南_Vue3_uni-app_HTML
前端·javascript·uni-app·html
志尊宝1 小时前
AI原生前端开发(042):AI辅助的路由设计与优化
javascript·react.js·ai-native
Dxy123931021612 小时前
JS DES 加密详解
开发语言·javascript·arcgis
充值内卷12 小时前
我给桌面加了个鱼缸:C++ 写后端,WebView2 里养一座 Three.js 小岛
开发语言·javascript·c++
椒哥14 小时前
一天被问几十次"允许",我统计了 517 次,然后写了个插件
前端·javascript·github
kyriewen15 小时前
我测了 6 种防请求竞态的写法:只有 1 种真能打
前端·javascript·程序员
OpsEye15 小时前
企业大模型压测,需要重点关注哪些指标?
javascript·ai编程
像我这样帅的人丶你还16 小时前
我html生成的doc文档为何在手机文档显示不了图片?
前端·javascript