Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
from PIL import Image | |
import io | |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋ | |
model = pipeline("image-classification", model="google/vit-base-patch16-224") | |
def classify_image(uploaded_image): | |
# ์ ๋ก๋๋ ์ด๋ฏธ์ง๊ฐ PIL ์ด๋ฏธ์ง ๊ฐ์ฒด์ธ์ง ํ์ธ (Gradio๋ ์๋์ผ๋ก PIL ์ด๋ฏธ์ง ๊ฐ์ฒด๋ก ๋ณํ) | |
if not isinstance(uploaded_image, Image.Image): | |
raise ValueError("Uploaded image is not in the correct format.") | |
predictions = model(uploaded_image) | |
return {prediction['label']: prediction['score'] for prediction in predictions} | |
# Gradio ์ธํฐํ์ด์ค ์์ฑ | |
iface = gr.Interface(fn=classify_image, | |
inputs=gr.Image(), | |
outputs=gr.Label(num_top_classes=3), | |
title="์ด๋ฏธ์ง ๋ถ๋ฅ๊ธฐ", | |
description="์ด๋ฏธ์ง๋ฅผ ์ ๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ์ต์์ 3๊ฐ์ ๋ถ๋ฅ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.", | |
share=True) # Public link ์์ฑ | |
# ์ธํฐํ์ด์ค ์คํ | |
iface.launch() | |