Spaces:
Build error
Build error
mochuan zhan commited on
Commit ·
455f3a3
1
Parent(s): 1d86318
fix + 2
Browse files
app.py
CHANGED
|
@@ -81,6 +81,10 @@ transform = transforms.Compose([
|
|
| 81 |
# 定义预测函数
|
| 82 |
def classify_image(image):
|
| 83 |
# image 已经是一个 PIL 图像
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
# 将图像转换为灰度模式
|
| 85 |
image = image.convert("L")
|
| 86 |
|
|
@@ -117,10 +121,10 @@ def classify_image(image):
|
|
| 117 |
|
| 118 |
iface = gr.Interface(
|
| 119 |
fn=classify_image,
|
| 120 |
-
inputs=gr.Sketchpad(crop_size=(256,256), type='
|
| 121 |
outputs=gr.Label(num_top_classes=1),
|
| 122 |
title="MNIST Digit Classification with ViT",
|
| 123 |
-
description="
|
| 124 |
)
|
| 125 |
|
| 126 |
|
|
|
|
| 81 |
# 定义预测函数
|
| 82 |
def classify_image(image):
|
| 83 |
# image 已经是一个 PIL 图像
|
| 84 |
+
# 将图像转换为灰度模式
|
| 85 |
+
if not isinstance(image, Image.Image):
|
| 86 |
+
raise TypeError(f"Expected image to be PIL Image, but got {type(image)}")
|
| 87 |
+
|
| 88 |
# 将图像转换为灰度模式
|
| 89 |
image = image.convert("L")
|
| 90 |
|
|
|
|
| 121 |
|
| 122 |
iface = gr.Interface(
|
| 123 |
fn=classify_image,
|
| 124 |
+
inputs=gr.Sketchpad(crop_size=(256,256), type='pil', image_mode='L', brush=gr.Brush()),
|
| 125 |
outputs=gr.Label(num_top_classes=1),
|
| 126 |
title="MNIST Digit Classification with ViT",
|
| 127 |
+
description="Use the mouse to hand draw a number and the model will predict the category it belongs to."
|
| 128 |
)
|
| 129 |
|
| 130 |
|