Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,18 @@
|
|
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")
|
8 |
|
9 |
def classify_image(uploaded_image):
|
10 |
-
#
|
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}
|
21 |
|
22 |
-
# Gradio ์ธํฐํ์ด์ค
|
23 |
iface = gr.Interface(fn=classify_image,
|
24 |
-
inputs=gr.Image(),
|
25 |
outputs=gr.Label(num_top_classes=3),
|
26 |
title="์ด๋ฏธ์ง ๋ถ๋ฅ๊ธฐ",
|
27 |
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ์ต์์ 3๊ฐ์ ๋ถ๋ฅ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.")
|
|
|
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")
|
7 |
|
8 |
def classify_image(uploaded_image):
|
9 |
+
# ์ด์ uploaded_image๋ ์๋์ผ๋ก PIL.Image ๊ฐ์ฒด์
๋๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
predictions = model(uploaded_image)
|
11 |
return {prediction['label']: prediction['score'] for prediction in predictions}
|
12 |
|
13 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ, type="pil"๋ก ์ค์ ํ์ฌ ์๋์ผ๋ก PIL.Image ๊ฐ์ฒด๋ก ๋ณํ๋๋๋ก ํจ
|
14 |
iface = gr.Interface(fn=classify_image,
|
15 |
+
inputs=gr.Image(type="pil"),
|
16 |
outputs=gr.Label(num_top_classes=3),
|
17 |
title="์ด๋ฏธ์ง ๋ถ๋ฅ๊ธฐ",
|
18 |
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ์ต์์ 3๊ฐ์ ๋ถ๋ฅ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.")
|