Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import gradio as gr
|
|
| 5 |
import spaces
|
| 6 |
import os
|
| 7 |
import uuid
|
|
|
|
| 8 |
|
| 9 |
# Importing the model-related functions
|
| 10 |
from stable_audio_tools import get_pretrained_model
|
|
@@ -17,12 +18,18 @@ def load_model():
|
|
| 17 |
print("Model loaded successfully.")
|
| 18 |
return model, model_config
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# Function to set up, generate, and process the audio
|
| 21 |
@spaces.GPU(duration=120) # Allocate GPU only when this function is called
|
| 22 |
def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
| 23 |
-
print(f"Prompt
|
| 24 |
-
print(f"Settings: Duration={seconds_total}s, Steps={steps}, CFG Scale={cfg_scale}")
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 27 |
print(f"Using device: {device}")
|
| 28 |
|
|
@@ -42,7 +49,7 @@ def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
|
| 42 |
|
| 43 |
# Set up text and timing conditioning
|
| 44 |
conditioning = [{
|
| 45 |
-
"prompt":
|
| 46 |
"seconds_start": 0,
|
| 47 |
"seconds_total": seconds_total
|
| 48 |
}]
|
|
@@ -88,17 +95,16 @@ footer {
|
|
| 88 |
}
|
| 89 |
"""
|
| 90 |
|
| 91 |
-
|
| 92 |
# Setting up the Gradio Interface
|
| 93 |
interface = gr.Interface(theme="Nymbo/Nymbo_Theme", css=css,
|
| 94 |
fn=generate_audio,
|
| 95 |
inputs=[
|
| 96 |
-
gr.Textbox(label="
|
| 97 |
-
gr.Slider(0, 47, value=30, label="
|
| 98 |
-
gr.Slider(10, 150, value=100, step=10, label="
|
| 99 |
-
gr.Slider(1, 15, value=7, step=0.1, label="CFG
|
| 100 |
],
|
| 101 |
-
outputs=gr.Audio(type="filepath", label="
|
| 102 |
)
|
| 103 |
|
| 104 |
# Pre-load the model to avoid multiprocessing issues
|
|
|
|
| 5 |
import spaces
|
| 6 |
import os
|
| 7 |
import uuid
|
| 8 |
+
from transformers import pipeline
|
| 9 |
|
| 10 |
# Importing the model-related functions
|
| 11 |
from stable_audio_tools import get_pretrained_model
|
|
|
|
| 18 |
print("Model loaded successfully.")
|
| 19 |
return model, model_config
|
| 20 |
|
| 21 |
+
# ๋ฒ์ญ ๋ชจ๋ธ ๋ก๋
|
| 22 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 23 |
+
|
| 24 |
# Function to set up, generate, and process the audio
|
| 25 |
@spaces.GPU(duration=120) # Allocate GPU only when this function is called
|
| 26 |
def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
| 27 |
+
print(f"Original Prompt: {prompt}")
|
|
|
|
| 28 |
|
| 29 |
+
# ํ๊ธ ํ
์คํธ๋ฅผ ์์ด๋ก ๋ฒ์ญ
|
| 30 |
+
translated_prompt = translator(prompt, max_length=512)[0]['translation_text']
|
| 31 |
+
print(f"Translated Prompt: {translated_prompt}")
|
| 32 |
+
|
| 33 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 34 |
print(f"Using device: {device}")
|
| 35 |
|
|
|
|
| 49 |
|
| 50 |
# Set up text and timing conditioning
|
| 51 |
conditioning = [{
|
| 52 |
+
"prompt": translated_prompt,
|
| 53 |
"seconds_start": 0,
|
| 54 |
"seconds_total": seconds_total
|
| 55 |
}]
|
|
|
|
| 95 |
}
|
| 96 |
"""
|
| 97 |
|
|
|
|
| 98 |
# Setting up the Gradio Interface
|
| 99 |
interface = gr.Interface(theme="Nymbo/Nymbo_Theme", css=css,
|
| 100 |
fn=generate_audio,
|
| 101 |
inputs=[
|
| 102 |
+
gr.Textbox(label="ํ๋กฌํํธ", placeholder="์ฌ๊ธฐ์ ํ
์คํธ ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ์ธ์"),
|
| 103 |
+
gr.Slider(0, 47, value=30, label="์ค๋์ค ๊ธธ์ด (์ด)"),
|
| 104 |
+
gr.Slider(10, 150, value=100, step=10, label="๋ํจ์ ๋จ๊ณ ์"),
|
| 105 |
+
gr.Slider(1, 15, value=7, step=0.1, label="CFG ์ค์ผ์ผ")
|
| 106 |
],
|
| 107 |
+
outputs=gr.Audio(type="filepath", label="์์ฑ๋ ์ค๋์ค"),
|
| 108 |
)
|
| 109 |
|
| 110 |
# Pre-load the model to avoid multiprocessing issues
|