gpt4 book ai didi

python - 使用小部件在 jupyter notebook 中显示 gif

转载 作者:行者123 更新时间:2023-12-04 10:25:37 26 4
gpt4 key购买 nike

您如何使用 python 小部件在 jupyeter 笔记本中显示 gif。

我试过了:

gif_box = widgets.Image("sample.gif")

或者
gif_box = widgets.Video("sample.gif")

但接收器错误:
TypeError: __init__() takes 1 positional argument but 2 were given

不管我怎么尝试都行不通

最佳答案

您需要将图像读入文件处理程序并将其读入字节字符串,然后才能将其传递到小部件中,如下所示:

# read file as bytes and get file handler. use `with` to ensure 
# your file is closed after you're done reading it
with open("sample.gif", "rb") as file:
# read file as string into `image`
image = file.read()

widgets.Image(
value=image,
format='gif'
)

docsImage小部件。

关于python - 使用小部件在 jupyter notebook 中显示 gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60640375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com