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