Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,42 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import
|
4 |
-
import os # os ๋ชจ๋์ ์ํฌํธํฉ๋๋ค.
|
5 |
|
6 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
7 |
image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
"
|
17 |
-
headers=headers,
|
18 |
-
json={"inputs": prompt, "parameters": {"length": 10}, "options": {"use_cache": False}}
|
19 |
)
|
20 |
-
|
21 |
-
#
|
22 |
return result
|
23 |
|
24 |
-
def
|
25 |
# ์ด๋ฏธ์ง ๋ถ๋ฅ
|
26 |
predictions = image_model(uploaded_image)
|
27 |
top_prediction = predictions[0]['label'] # ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ๋ถ๋ฅ ๊ฒฐ๊ณผ
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
|
32 |
-
#
|
33 |
-
|
|
|
34 |
|
35 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
36 |
iface = gr.Interface(
|
37 |
-
fn=
|
38 |
inputs=gr.Image(type="pil"),
|
39 |
outputs=[gr.Label(), gr.Audio()],
|
40 |
-
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ
|
41 |
-
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด,
|
42 |
)
|
43 |
|
44 |
# ์ธํฐํ์ด์ค ์คํ
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from gradio_client import Client # ๊ฐ์ : gradio_client ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
|
|
|
4 |
|
5 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
6 |
image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
7 |
|
8 |
+
def generate_voice(prompt):
|
9 |
+
# Tango API๋ฅผ ์ฌ์ฉํ์ฌ ์์ฑ ์์ฑ
|
10 |
+
client = Client("https://declare-lab-tango.hf.space/")
|
11 |
+
result = client.predict(
|
12 |
+
prompt, # ์ด๋ฏธ์ง ๋ถ๋ฅ ๊ฒฐ๊ณผ๋ฅผ ํ๋กฌํํธ๋ก ์ฌ์ฉ
|
13 |
+
100, # Steps
|
14 |
+
1, # Guidance Scale
|
15 |
+
api_name="/predict" # API ์๋ํฌ์ธํธ ๊ฒฝ๋ก
|
|
|
|
|
16 |
)
|
17 |
+
# Tango API ํธ์ถ ๊ฒฐ๊ณผ ์ฒ๋ฆฌ
|
18 |
+
# ์: result์์ ์์ฑ ํ์ผ URL ๋๋ ๋ฐ์ดํฐ ์ถ์ถ
|
19 |
return result
|
20 |
|
21 |
+
def classify_and_generate_voice(uploaded_image):
|
22 |
# ์ด๋ฏธ์ง ๋ถ๋ฅ
|
23 |
predictions = image_model(uploaded_image)
|
24 |
top_prediction = predictions[0]['label'] # ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ ๋ถ๋ฅ ๊ฒฐ๊ณผ
|
25 |
|
26 |
+
# ์์ฑ ์์ฑ
|
27 |
+
voice_result = generate_voice(top_prediction)
|
28 |
|
29 |
+
# ๋ฐํ๋ ์์ฑ ๊ฒฐ๊ณผ๋ฅผ Gradio ์ธํฐํ์ด์ค๋ก ์ ๋ฌ
|
30 |
+
# ์: voice_result['url'] ๋๋ voice_result['audio_data'] ๋ฑ
|
31 |
+
return top_prediction, voice_result
|
32 |
|
33 |
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
34 |
iface = gr.Interface(
|
35 |
+
fn=classify_and_generate_voice,
|
36 |
inputs=gr.Image(type="pil"),
|
37 |
outputs=[gr.Label(), gr.Audio()],
|
38 |
+
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ ์์ฑ ์์ฑ",
|
39 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ํด๋นํ๋ ์์ฑ์ ์์ฑํฉ๋๋ค."
|
40 |
)
|
41 |
|
42 |
# ์ธํฐํ์ด์ค ์คํ
|