Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,23 @@
|
|
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 |
-
hugging_face_auth_token = os.getenv("HUGGING_FACE_AUTH_TOKEN")
|
9 |
-
|
10 |
def get_audiogen(prompt):
|
11 |
# ์ค๋์ค ์์ฑ ๋ชจ๋ธ API ํธ์ถ
|
12 |
response = requests.post(
|
13 |
"https://api-inference.huggingface.co/models/fffiloni/audiogen",
|
14 |
-
headers={"Authorization": "Bearer
|
15 |
json={"inputs": prompt, "parameters": {"length": 10}, "options": {"use_cache": False}}
|
16 |
)
|
17 |
result = response.json()
|
18 |
-
#
|
19 |
-
# ์: ์์ฑ๋ ์ค๋์ค ํ์ผ์ URL์ ๋ฐํํ๊ฑฐ๋, ์ค๋์ค ๋ฐ์ดํฐ ์์ฒด๋ฅผ ๋ฐํํ ์ ์์ต๋๋ค.
|
20 |
return result
|
21 |
|
22 |
def classify_and_generate_audio(uploaded_image):
|
@@ -27,8 +28,7 @@ def classify_and_generate_audio(uploaded_image):
|
|
27 |
# ์ค๋์ค ์์ฑ
|
28 |
audio_result = get_audiogen(top_prediction)
|
29 |
|
30 |
-
# audio_result๋ฅผ ์ฒ๋ฆฌํ์ฌ Gradio๊ฐ ์ฌ์ํ ์ ์๋ ํ์์ผ๋ก
|
31 |
-
# ์: audio_result['url'] ๋๋ audio_result['audio_data'] ๋ฑ
|
32 |
return top_prediction, audio_result
|
33 |
|
34 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
@@ -42,4 +42,3 @@ iface = gr.Interface(
|
|
42 |
|
43 |
# ์ธํฐํ์ด์ค ์คํ
|
44 |
iface.launch()
|
45 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import requests
|
4 |
+
import os
|
5 |
+
|
6 |
+
# ํ๊ฒฝ๋ณ์์์ Hugging Face API ํ ํฐ์ ๋ก๋
|
7 |
+
hugging_face_auth_token = os.getenv("HUGGING_FACE_AUTH_TOKEN")
|
8 |
|
9 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
10 |
image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
11 |
|
|
|
|
|
12 |
def get_audiogen(prompt):
|
13 |
# ์ค๋์ค ์์ฑ ๋ชจ๋ธ API ํธ์ถ
|
14 |
response = requests.post(
|
15 |
"https://api-inference.huggingface.co/models/fffiloni/audiogen",
|
16 |
+
headers={"Authorization": f"Bearer {hugging_face_auth_token}"}, # ์์ ๋ ๋ถ๋ถ
|
17 |
json={"inputs": prompt, "parameters": {"length": 10}, "options": {"use_cache": False}}
|
18 |
)
|
19 |
result = response.json()
|
20 |
+
# ์์ฑ๋ ์ค๋์ค ํ์ผ์ URL์ ๋ฐํํ๊ฑฐ๋, ์ค๋์ค ๋ฐ์ดํฐ ์์ฒด๋ฅผ ๋ฐํ
|
|
|
21 |
return result
|
22 |
|
23 |
def classify_and_generate_audio(uploaded_image):
|
|
|
28 |
# ์ค๋์ค ์์ฑ
|
29 |
audio_result = get_audiogen(top_prediction)
|
30 |
|
31 |
+
# audio_result๋ฅผ ์ฒ๋ฆฌํ์ฌ Gradio๊ฐ ์ฌ์ํ ์ ์๋ ํ์์ผ๋ก ๋ฐํ
|
|
|
32 |
return top_prediction, audio_result
|
33 |
|
34 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
|
|
42 |
|
43 |
# ์ธํฐํ์ด์ค ์คํ
|
44 |
iface.launch()
|
|