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