Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,16 @@
|
|
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 |
-
# ์นดํ
๊ณ ๋ฆฌ์ ๋ฐ๋ฅธ ์ฌ์ด๋
|
8 |
-
|
9 |
-
"dog": "
|
10 |
-
"cat": "
|
11 |
-
# ... ๊ฐ ์นดํ
๊ณ ๋ฆฌ์ ๋ํ ์ฌ์ด๋ ํ์ผ
|
12 |
}
|
13 |
|
14 |
def classify_image(uploaded_image):
|
@@ -16,17 +18,23 @@ def classify_image(uploaded_image):
|
|
16 |
# ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ด
|
17 |
top_prediction = predictions[0]['label']
|
18 |
|
19 |
-
# ์์ธก ๊ฒฐ๊ณผ์ ํด๋นํ๋ ์ฌ์ด๋
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ํด๋นํ๋
|
30 |
)
|
31 |
|
32 |
# ์ธํฐํ์ด์ค ์คํ
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import soundfile as sf
|
4 |
+
import io
|
5 |
|
6 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
7 |
model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
8 |
|
9 |
+
# ์นดํ
๊ณ ๋ฆฌ์ ๋ฐ๋ฅธ ์ฌ์ด๋ ํ์ผ์ ๊ฒฝ๋ก๋ฅผ ์ ์
|
10 |
+
sound_files = {
|
11 |
+
"dog": "path/to/dog_bark.wav",
|
12 |
+
"cat": "path/to/cat_meow.wav",
|
13 |
+
# ... ๊ฐ ์นดํ
๊ณ ๋ฆฌ์ ๋ํ ์ฌ์ด๋ ํ์ผ ๊ฒฝ๋ก ์ถ๊ฐ
|
14 |
}
|
15 |
|
16 |
def classify_image(uploaded_image):
|
|
|
18 |
# ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ด
|
19 |
top_prediction = predictions[0]['label']
|
20 |
|
21 |
+
# ์์ธก ๊ฒฐ๊ณผ์ ํด๋นํ๋ ์ฌ์ด๋ ํ์ผ์ ๋ก๋
|
22 |
+
sound_path = sound_files.get(top_prediction, None)
|
23 |
+
if sound_path is not None:
|
24 |
+
with open(sound_path, 'rb') as file:
|
25 |
+
audio_data = file.read()
|
26 |
+
return top_prediction, audio_data
|
27 |
+
else:
|
28 |
+
# ํด๋นํ๋ ์ฌ์ด๋ ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ๋น ์ค๋์ค ๋ฐ์ดํฐ ๋ฐํ
|
29 |
+
return top_prediction, None
|
30 |
|
31 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
32 |
iface = gr.Interface(
|
33 |
fn=classify_image,
|
34 |
inputs=gr.Image(type="pil"),
|
35 |
+
outputs=[gr.Label(), gr.Audio(format="wav")],
|
36 |
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ ์ฌ์ด๋ ์ฌ์",
|
37 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ํด๋นํ๋ ์ฌ์ด๋๋ฅผ ์ฌ์ํฉ๋๋ค."
|
38 |
)
|
39 |
|
40 |
# ์ธํฐํ์ด์ค ์คํ
|