Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
|
4 |
|
5 |
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
|
6 |
image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
|
7 |
|
8 |
def generate_voice(prompt):
|
9 |
-
# Tango API๋ฅผ ์ฌ์ฉํ์ฌ ์์ฑ ์์ฑ
|
10 |
-
|
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 |
# ์ธํฐํ์ด์ค ์คํ
|
43 |
-
iface.launch()
|
44 |
-
|
45 |
-
examples = [['./dog.jpg'],]
|
46 |
-
demo = gr.Interface(fn=process,inputs="image", outputs="image", examples=examples, title=title, description=description)
|
47 |
-
|
48 |
if __name__ == "__main__":
|
49 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
# 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 |
+
return "https://example.com/generated_voice.mp3" # ์์ ์์ฑ ํ์ผ URL ๋ฐํ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def classify_and_generate_voice(uploaded_image):
|
13 |
# ์ด๋ฏธ์ง ๋ถ๋ฅ
|
14 |
predictions = image_model(uploaded_image)
|
15 |
+
top_prediction = predictions[0]['label']
|
|
|
16 |
# ์์ฑ ์์ฑ
|
17 |
voice_result = generate_voice(top_prediction)
|
|
|
|
|
|
|
18 |
return top_prediction, voice_result
|
19 |
|
20 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ ๋ฐ ์์ ์ด๋ฏธ์ง ์ค์
|
21 |
iface = gr.Interface(
|
22 |
fn=classify_and_generate_voice,
|
23 |
inputs=gr.Image(type="pil"),
|
24 |
outputs=[gr.Label(), gr.Audio()],
|
25 |
+
examples=[["dog.jpg"]], # ์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก๋ฅผ ๋ฆฌ์คํธ๋ก ์ถ๊ฐ
|
26 |
title="์ด๋ฏธ์ง ๋ถ๋ฅ ๋ฐ ์์ฑ ์์ฑ",
|
27 |
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด, ์ฌ๋ฌผ์ ์ธ์ํ๊ณ ํด๋นํ๋ ์์ฑ์ ์์ฑํฉ๋๋ค."
|
28 |
)
|
29 |
|
30 |
# ์ธํฐํ์ด์ค ์คํ
|
|
|
|
|
|
|
|
|
|
|
31 |
if __name__ == "__main__":
|
32 |
+
iface.launch(share=True)
|