Update docs to use new Image init (#9304)

This commit is contained in:
Tayfun Sen 2024-09-10 06:45:12 +01:00 committed by GitHub
parent bcb3a2b9a0
commit 278af1995b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 7 additions and 7 deletions

View File

@ -49,7 +49,7 @@ When using the `Image` component as input, your function will receive a NumPy ar
Gradio handles the preprocessing and postprocessing to convert images to NumPy arrays and vice versa. You can also control the preprocessing performed with the `type=` keyword argument. For example, if you wanted your function to take a file path to an image instead of a NumPy array, the input `Image` component could be written as:
```python
gr.Image(type="filepath", shape=...)
gr.Image(type="filepath")
```
You can read more about the built-in Gradio components and how to customize them in the [Gradio docs](https://gradio.app/docs).

View File

@ -73,7 +73,7 @@ def sepia(input_img):
sepia_img /= sepia_img.max()
return sepia_img
demo = gr.Interface(sepia, gr.Image(shape=(200, 200)), "image")
demo = gr.Interface(sepia, gr.Image(width=200, height=200), "image")
demo.launch()
```
@ -121,4 +121,4 @@ The `Example.svelte` file and `process_example()` method will be covered in grea
## Conclusion
Now that you know the most important pieces to remember about Gradio components, you can start to design and build your own!
Now that you know the most important pieces to remember about Gradio components, you can start to design and build your own!

View File

@ -71,7 +71,7 @@ Finally, we'll add one more parameter, the `examples`, which allows us to prepop
import gradio as gr
gr.Interface(fn=classify_image,
inputs=gr.Image(shape=(224, 224)),
inputs=gr.Image(width=224, height=224),
outputs=gr.Label(num_top_classes=3),
examples=["banana.jpg", "car.jpg"]).launch()
```

View File

@ -78,7 +78,7 @@ $demo_sepia_filter
您还可以使用 `type=` 关键字参数设置组件使用的数据类型。例如,如果您希望函数接受图像文件路径而不是 NumPy 数组,输入 `Image` 组件可以写成:
```python
gr.Image(type="filepath", shape=...)
gr.Image(type="filepath")
```
还要注意,我们的输入 `Image` 组件附带有一个编辑按钮🖉,允许裁剪和缩放图像。通过这种方式操作图像可以帮助揭示机器学习模型中的偏见或隐藏的缺陷!

View File

@ -106,7 +106,7 @@ im/1.png,Output/1.png
您可以使用构建图像组件时的参数控制*预处理*。例如,如果您使用以下参数实例化 `Image` 组件,它将将图像转换为 `PIL` 类型,并将其重塑为`(100, 100)`,而不管提交时的原始大小如何:
```py
img = gr.Image(shape=(100, 100), type="pil")
img = gr.Image(width=100, height=100, type="pil")
```
相反,这里我们保留图像的原始大小,但在将其转换为 numpy 数组之前反转颜色:

View File

@ -72,7 +72,7 @@ def classify_image(inp):
import gradio as gr
gr.Interface(fn=classify_image,
inputs=gr.Image(shape=(224, 224)),
inputs=gr.Image(width=224, height=224),
outputs=gr.Label(num_top_classes=3),
examples=["banana.jpg", "car.jpg"]).launch()
```