Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
|
|
|
|
|
|
4 |
|
5 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
6 |
model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def classify_image(uploaded_image):
|
9 |
-
# ์ด์ uploaded_image๋ ์๋์ผ๋ก PIL.Image ๊ฐ์ฒด์
๋๋ค.
|
10 |
predictions = model(uploaded_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
return {prediction['label']: prediction['score'] for prediction in predictions}
|
12 |
|
13 |
-
# Gradio ์ธํฐํ์ด์ค
|
14 |
iface = gr.Interface(fn=classify_image,
|
15 |
inputs=gr.Image(type="pil"),
|
16 |
outputs=gr.Label(num_top_classes=3),
|
17 |
-
title="์ด๋ฏธ์ง
|
18 |
-
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ
|
19 |
|
20 |
# ์ธํฐํ์ด์ค ์คํ
|
21 |
iface.launch()
|
|
|
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 |
+
sound_files = {
|
13 |
+
"dog": "dog_bark.mp3",
|
14 |
+
"cat": "cat_meow.mp3",
|
15 |
+
# ... ๊ฐ ์นดํ
๊ณ ๋ฆฌ์ ๋ํ ์ฌ์ด๋ ํ์ผ ๊ฒฝ๋ก ์ถ๊ฐ
|
16 |
+
}
|
17 |
+
|
18 |
def classify_image(uploaded_image):
|
|
|
19 |
predictions = model(uploaded_image)
|
20 |
+
# ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ์์ธก ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ด
|
21 |
+
top_prediction = predictions[0]['label']
|
22 |
+
|
23 |
+
# ์์ธก ๊ฒฐ๊ณผ์ ํด๋นํ๋ ์ฌ์ด๋ ํ์ผ์ ์ฌ์
|
24 |
+
if top_prediction in sound_files:
|
25 |
+
sound_path = sound_files[top_prediction]
|
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(fn=classify_image,
|
33 |
inputs=gr.Image(type="pil"),
|
34 |
outputs=gr.Label(num_top_classes=3),
|
35 |
+
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ ์ฌ์ด๋ ์ฌ์",
|
36 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ํด๋นํ๋ ์ํฅ์ ์ฌ์ํฉ๋๋ค.")
|
37 |
|
38 |
# ์ธํฐํ์ด์ค ์คํ
|
39 |
iface.launch()
|