Spaces:
Running
Running
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
from PIL import Image
|
4 |
-
from pydub import AudioSegment
|
5 |
-
from pydub.playback import play
|
6 |
-
import io
|
7 |
|
8 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
9 |
model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
10 |
|
11 |
-
# ์นดํ
๊ณ ๋ฆฌ์ ๋ฐ๋ฅธ ์ฌ์ด๋ ํ์ผ
|
12 |
-
|
13 |
-
"dog": "dog_bark.mp3",
|
14 |
-
"cat": "cat_meow.mp3",
|
15 |
-
# ... ๊ฐ ์นดํ
๊ณ ๋ฆฌ์ ๋ํ ์ฌ์ด๋ ํ์ผ
|
16 |
}
|
17 |
|
18 |
def classify_image(uploaded_image):
|
@@ -20,20 +16,18 @@ def classify_image(uploaded_image):
|
|
20 |
# ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ด
|
21 |
top_prediction = predictions[0]['label']
|
22 |
|
23 |
-
# ์์ธก ๊ฒฐ๊ณผ์ ํด๋นํ๋ ์ฌ์ด๋
|
24 |
-
|
25 |
-
|
26 |
-
sound = AudioSegment.from_file(sound_path)
|
27 |
-
play(sound)
|
28 |
-
|
29 |
-
return {prediction['label']: prediction['score'] for prediction in predictions}
|
30 |
|
31 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
32 |
-
iface = gr.Interface(
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
37 |
|
38 |
# ์ธํฐํ์ด์ค ์คํ
|
39 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
5 |
model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
6 |
|
7 |
+
# ์นดํ
๊ณ ๋ฆฌ์ ๋ฐ๋ฅธ ์ฌ์ด๋ ํ์ผ URL์ ์ ์
|
8 |
+
sound_urls = {
|
9 |
+
"dog": "https://example.com/dog_bark.mp3",
|
10 |
+
"cat": "https://example.com/cat_meow.mp3",
|
11 |
+
# ... ๊ฐ ์นดํ
๊ณ ๋ฆฌ์ ๋ํ ์ฌ์ด๋ ํ์ผ URL ์ถ๊ฐ
|
12 |
}
|
13 |
|
14 |
def classify_image(uploaded_image):
|
|
|
16 |
# ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ด
|
17 |
top_prediction = predictions[0]['label']
|
18 |
|
19 |
+
# ์์ธก ๊ฒฐ๊ณผ์ ํด๋นํ๋ ์ฌ์ด๋ ํ์ผ์ URL์ ๋ฐํ
|
20 |
+
sound_url = sound_urls.get(top_prediction, None)
|
21 |
+
return top_prediction, sound_url
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=classify_image,
|
26 |
+
inputs=gr.Image(type="pil"),
|
27 |
+
outputs=[gr.Label(), gr.Audio()],
|
28 |
+
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ ์ฌ์ด๋ ์ฌ์",
|
29 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ํด๋นํ๋ ์ฌ์ด๋์ URL์ ๋ฐํํฉ๋๋ค."
|
30 |
+
)
|
31 |
|
32 |
# ์ธํฐํ์ด์ค ์คํ
|
33 |
iface.launch()
|