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