Spaces:
Runtime error
Runtime error
File size: 1,116 Bytes
2bd9468 9902a40 891d8e1 2bd9468 23708c8 87c119f 9902a40 87c119f 23708c8 2bd9468 87c119f 23708c8 2bd9468 3382a71 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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()
|