Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,43 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import
|
4 |
|
5 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
top_prediction = predictions[0]['label']
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
else:
|
27 |
-
# ํด๋นํ๋ ์ฌ์ด๋ ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ๋น ์ค๋์ค ๋ฐ์ดํฐ ๋ฐํ
|
28 |
-
return top_prediction, None
|
29 |
|
30 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
31 |
iface = gr.Interface(
|
32 |
-
fn=
|
33 |
inputs=gr.Image(type="pil"),
|
34 |
-
outputs=[gr.Label(), gr.Audio(
|
35 |
-
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ
|
36 |
-
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด,
|
37 |
)
|
38 |
|
39 |
# ์ธํฐํ์ด์ค ์คํ
|
40 |
iface.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import requests
|
4 |
|
5 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
6 |
+
image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
7 |
|
8 |
+
def get_audiogen(prompt):
|
9 |
+
# ์ค๋์ค ์์ฑ ๋ชจ๋ธ API ํธ์ถ
|
10 |
+
response = requests.post(
|
11 |
+
"https://api-inference.huggingface.co/models/fffiloni/audiogen",
|
12 |
+
headers={"Authorization": "/infer"},
|
13 |
+
json={"inputs": prompt, "parameters": {"length": 10}, "options": {"use_cache": False}}
|
14 |
+
)
|
15 |
+
result = response.json()
|
16 |
+
# ์ฌ๊ธฐ์์ result ์ฒ๋ฆฌ ๋ก์ง์ ๊ตฌํํฉ๋๋ค.
|
17 |
+
# ์: ์์ฑ๋ ์ค๋์ค ํ์ผ์ URL์ ๋ฐํํ๊ฑฐ๋, ์ค๋์ค ๋ฐ์ดํฐ ์์ฒด๋ฅผ ๋ฐํํ ์ ์์ต๋๋ค.
|
18 |
+
return result
|
19 |
|
20 |
+
def classify_and_generate_audio(uploaded_image):
|
21 |
+
# ์ด๋ฏธ์ง ๋ถ๋ฅ
|
22 |
+
predictions = image_model(uploaded_image)
|
23 |
+
top_prediction = predictions[0]['label'] # ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ๋ถ๋ฅ ๊ฒฐ๊ณผ
|
24 |
|
25 |
+
# ์ค๋์ค ์์ฑ
|
26 |
+
audio_result = get_audiogen(top_prediction)
|
27 |
+
|
28 |
+
# audio_result๋ฅผ ์ฒ๋ฆฌํ์ฌ Gradio๊ฐ ์ฌ์ํ ์ ์๋ ํ์์ผ๋ก ๋ฐํํฉ๋๋ค.
|
29 |
+
# ์: audio_result['url'] ๋๋ audio_result['audio_data'] ๋ฑ
|
30 |
+
return top_prediction, audio_result
|
|
|
|
|
|
|
31 |
|
32 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
33 |
iface = gr.Interface(
|
34 |
+
fn=classify_and_generate_audio,
|
35 |
inputs=gr.Image(type="pil"),
|
36 |
+
outputs=[gr.Label(), gr.Audio()],
|
37 |
+
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ ์ค๋์ค ์์ฑ",
|
38 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ด๋ฏธ์ง๋ฅผ ๋ถ์ํ์ฌ ๋ฌด์์ธ์ง ์ค๋ช
ํ๊ณ , ํด๋นํ๋ ์ค๋์ค๋ฅผ ์์ฑํฉ๋๋ค."
|
39 |
)
|
40 |
|
41 |
# ์ธํฐํ์ด์ค ์คํ
|
42 |
iface.launch()
|
43 |
+
|