Spaces:
Runtime error
Runtime error
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)
|