pip install transformers import gradio as gr from PIL import Image from transformers import AutoModelForImageClassification, AutoTokenizer, pipeline # Hugging Face 모델 및 토크나이저 로드 model_name = "patrickvonplaten/bert2bert_coco" model = AutoModelForImageClassification.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) classifier = pipeline("image-classification", model=model, tokenizer=tokenizer) def classify_image(image): # 이미지 분류 result = classifier(image) predictions = {prediction['label']: prediction['score'] for prediction in result} return predictions inputs = gr.inputs.Image(type="pil", label="Upload an image") outputs = gr.outputs.Label(num_top_classes=3) gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs).launch()