import gradio as gr from transformers import pipeline # 이미지 인식 파이프라인 로드 model = pipeline("image-classification", model="google/vit-base-patch16-224") # 카테고리에 따른 사운드 파일 URL을 정의 sound_urls = { "dog": "https://example.com/dog_bark.mp3", "cat": "https://example.com/cat_meow.mp3", # ... 각 카테고리에 대한 사운드 파일 URL 추가 } def classify_image(uploaded_image): predictions = model(uploaded_image) # 가장 확률이 높은 예측 결과를 가져옴 top_prediction = predictions[0]['label'] # 예측 결과에 해당하는 사운드 파일의 URL을 반환 sound_url = sound_urls.get(top_prediction, None) return top_prediction, sound_url # Gradio 인터페이스 생성 iface = gr.Interface( fn=classify_image, inputs=gr.Image(type="pil"), outputs=[gr.Label(), gr.Audio()], title="이미지 분류 및 사운드 재생", description="이미지를 업로드하면, 사물을 인식하고 해당하는 사운드의 URL을 반환합니다." ) # 인터페이스 실행 iface.launch()