import gradio as gr from transformers import pipeline from PIL import Image # 이미지 인식 파이프라인 로드 model = pipeline("image-classification", model="google/vit-base-patch16-224") def classify_image(uploaded_image): # 이제 uploaded_image는 자동으로 PIL.Image 객체입니다. predictions = model(uploaded_image) return {prediction['label']: prediction['score'] for prediction in predictions} # Gradio 인터페이스 생성, type="pil"로 설정하여 자동으로 PIL.Image 객체로 변환되도록 함 iface = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil"), outputs=gr.Label(num_top_classes=3), title="이미지 분류기", description="이미지를 업로드하면, 사물을 인식하고 최상위 3개의 분류 결과를 출력합니다.") # 인터페이스 실행 iface.launch()