Spaces:
Runtime error
Runtime error
File size: 1,645 Bytes
2bd9468 8770d52 158913f 2bd9468 9902a40 8770d52 2bd9468 158913f ef8b4e2 8770d52 ef8b4e2 8770d52 ef8b4e2 8770d52 158913f 8770d52 87c119f 8770d52 87c119f 8770d52 c034f68 8770d52 2bd9468 87c119f 23708c8 8770d52 23708c8 8770d52 23708c8 2bd9468 3382a71 |
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 45 46 |
import gradio as gr
from transformers import pipeline
import requests
import os # os ๋ชจ๋์ ์ํฌํธํฉ๋๋ค.
# ์ด๋ฏธ์ง ์ธ์ ํ์ดํ๋ผ์ธ ๋ก๋
image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
# ํ๊ฒฝ ๋ณ์์์ Hugging Face API ํ ํฐ ๋ก๋
hugging_face_auth_token = os.getenv("HUGGING_FACE_AUTH_TOKEN")
def get_audiogen(prompt):
# ์ค๋์ค ์์ฑ ๋ชจ๋ธ API ํธ์ถ
headers = {"Authorization": f"Bearer {hugging_face_auth_token}"}
response = requests.post(
"https://api-inference.huggingface.co/models/fffiloni/audiogen",
headers=headers,
json={"inputs": prompt, "parameters": {"length": 10}, "options": {"use_cache": False}}
)
result = response.json()
# ์ฌ๊ธฐ์์ result ์ฒ๋ฆฌ ๋ก์ง์ ๊ตฌํํฉ๋๋ค.
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๊ฐ ์ฌ์ํ ์ ์๋ ํ์์ผ๋ก ๋ฐํ
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()
|