源代码
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)