Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
6 |
model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
@@ -8,9 +9,12 @@ model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
|
8 |
def classify_image(uploaded_image):
|
9 |
# ์
๋ก๋๋ ์ด๋ฏธ์ง๊ฐ PIL ์ด๋ฏธ์ง ๊ฐ์ฒด๊ฐ ์๋ ๊ฒฝ์ฐ ๋ณํ
|
10 |
if not isinstance(uploaded_image, Image.Image):
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
predictions = model(uploaded_image)
|
16 |
return {prediction['label']: prediction['score'] for prediction in predictions}
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
4 |
+
import io
|
5 |
|
6 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
7 |
model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
|
|
9 |
def classify_image(uploaded_image):
|
10 |
# ์
๋ก๋๋ ์ด๋ฏธ์ง๊ฐ PIL ์ด๋ฏธ์ง ๊ฐ์ฒด๊ฐ ์๋ ๊ฒฝ์ฐ ๋ณํ
|
11 |
if not isinstance(uploaded_image, Image.Image):
|
12 |
+
try:
|
13 |
+
# ์
๋ก๋๋ ์ด๋ฏธ์ง ๋ฐ์ดํฐ๋ฅผ PIL ์ด๋ฏธ์ง ๊ฐ์ฒด๋ก ๋ณํ
|
14 |
+
uploaded_image = Image.open(io.BytesIO(uploaded_image))
|
15 |
+
except Exception as e:
|
16 |
+
# ๋ณํ ์ค ๋ฐ์ํ ์ค๋ฅ ์ฒ๋ฆฌ
|
17 |
+
raise ValueError("Cannot convert the uploaded image to a PIL Image object: " + str(e))
|
18 |
|
19 |
predictions = model(uploaded_image)
|
20 |
return {prediction['label']: prediction['score'] for prediction in predictions}
|