Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,75 +9,127 @@ classifier = pipeline("audio-classification", model="dima806/music_genres_classi
|
|
| 9 |
mastering_client = Client("amaai-lab/SonicMaster")
|
| 10 |
image_client = Client("black-forest-labs/FLUX.1-schnell")
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
results = classifier(audio_path)
|
| 15 |
genre = results[0]['label']
|
| 16 |
|
| 17 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
result = mastering_client.predict(
|
| 19 |
handle_file(audio_path),
|
| 20 |
-
|
| 21 |
-
42,
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
def art_logic(status_text, vibe):
|
| 29 |
if not status_text or "Ready" in status_text: return None
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
img_result = image_client.predict(
|
| 33 |
-
prompt=
|
| 34 |
-
seed=0,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
api_name="/infer"
|
| 36 |
)
|
| 37 |
return img_result[0]
|
| 38 |
|
| 39 |
-
def video_logic(audio_path, image_path):
|
| 40 |
if not audio_path or not image_path: return None
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
img = ImageClip(image_path).with_duration(audio.duration).resized(width=1080)
|
|
|
|
|
|
|
| 43 |
video = img.on_color(size=(1080, 1920), color=(15, 15, 15), pos="center").with_audio(audio)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
return mastered if "Mastered" in choice else raw
|
| 49 |
|
| 50 |
-
# --- UI ---
|
| 51 |
-
with gr.Blocks() as demo:
|
| 52 |
-
gr.
|
|
|
|
| 53 |
raw_storage = gr.State()
|
| 54 |
master_storage = gr.State()
|
| 55 |
|
| 56 |
with gr.Tabs():
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
master_btn = gr.Button("π MASTER", variant="primary")
|
| 60 |
with gr.Row():
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 9 |
mastering_client = Client("amaai-lab/SonicMaster")
|
| 10 |
image_client = Client("black-forest-labs/FLUX.1-schnell")
|
| 11 |
|
| 12 |
+
# --- LOGIC ---
|
| 13 |
+
|
| 14 |
+
def master_logic(audio_path, brightness, loudness, reverb, steps, cfg):
|
| 15 |
+
if not audio_path: return None, None, "β οΈ Upload audio!", None
|
| 16 |
+
|
| 17 |
+
# 1. Detect Genre
|
| 18 |
results = classifier(audio_path)
|
| 19 |
genre = results[0]['label']
|
| 20 |
|
| 21 |
+
# 2. Map Sliders to AI Instructions
|
| 22 |
+
bright_txt = "increase high-end clarity and brightness" if brightness > 7 else ("warm vintage roll-off" if brightness < 3 else "balanced EQ")
|
| 23 |
+
loud_txt = "aggressive limiting for maximum loudness" if loudness > 7 else ("wide natural dynamic range" if loudness < 3 else "standard radio compression")
|
| 24 |
+
verb_txt = "spacious hall reverb" if reverb > 7 else ("dry intimate studio sound" if reverb < 3 else "natural room acoustics")
|
| 25 |
+
|
| 26 |
+
full_prompt = f"Professional {genre} studio master, {bright_txt}, {loud_txt}, {verb_txt}."
|
| 27 |
+
|
| 28 |
+
# 3. AI Mastering API
|
| 29 |
result = mastering_client.predict(
|
| 30 |
handle_file(audio_path),
|
| 31 |
+
full_prompt,
|
| 32 |
+
42, # Seed
|
| 33 |
+
int(steps),
|
| 34 |
+
float(cfg)
|
| 35 |
)
|
| 36 |
|
| 37 |
+
mastered_file = result[0] # The actual downloaded file
|
| 38 |
+
status_msg = f"β
**{genre}** Mastered with {int(steps)} steps at {cfg} intensity."
|
| 39 |
+
|
| 40 |
+
return mastered_file, mastered_file, status_msg, mastered_file
|
| 41 |
|
| 42 |
+
def art_logic(status_text, vibe, detail_steps, creativity_cfg):
|
| 43 |
if not status_text or "Ready" in status_text: return None
|
| 44 |
+
|
| 45 |
+
genre = status_text.split("**")[1] if "**" in status_text else "Music"
|
| 46 |
+
prompt = f"Professional album cover art, {genre} style, {vibe}, 4k, ultra-detailed, no text."
|
| 47 |
|
| 48 |
img_result = image_client.predict(
|
| 49 |
+
prompt=prompt,
|
| 50 |
+
seed=0,
|
| 51 |
+
width=1024,
|
| 52 |
+
height=1024,
|
| 53 |
+
guidance_scale=float(creativity_cfg),
|
| 54 |
+
num_inference_steps=int(detail_steps),
|
| 55 |
api_name="/infer"
|
| 56 |
)
|
| 57 |
return img_result[0]
|
| 58 |
|
| 59 |
+
def video_logic(audio_path, image_path, volume_level):
|
| 60 |
if not audio_path or not image_path: return None
|
| 61 |
+
|
| 62 |
+
# Load and adjust levels
|
| 63 |
+
audio = AudioFileClip(audio_path).subclipped(0, 30).volumex(volume_level)
|
| 64 |
img = ImageClip(image_path).with_duration(audio.duration).resized(width=1080)
|
| 65 |
+
|
| 66 |
+
# Composition
|
| 67 |
video = img.on_color(size=(1080, 1920), color=(15, 15, 15), pos="center").with_audio(audio)
|
| 68 |
+
|
| 69 |
+
out_path = "final_promo.mp4"
|
| 70 |
+
video.write_videofile(out_path, fps=24, codec="libx264", audio_codec="aac")
|
| 71 |
+
return out_path
|
|
|
|
| 72 |
|
| 73 |
+
# --- UI LAYOUT ---
|
| 74 |
+
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 75 |
+
gr.HTML("<h1 style='text-align: center;'>ποΈ AI Studio: Effect Console</h1>")
|
| 76 |
+
|
| 77 |
raw_storage = gr.State()
|
| 78 |
master_storage = gr.State()
|
| 79 |
|
| 80 |
with gr.Tabs():
|
| 81 |
+
# TAB 1: MASTERING
|
| 82 |
+
with gr.TabItem("π§ Mastering Console"):
|
|
|
|
| 83 |
with gr.Row():
|
| 84 |
+
with gr.Column(scale=1):
|
| 85 |
+
in_audio = gr.Audio(label="Raw Upload", type="filepath")
|
| 86 |
+
master_btn = gr.Button("π APPLY MASTERING", variant="primary")
|
| 87 |
+
|
| 88 |
+
with gr.Column(scale=1):
|
| 89 |
+
gr.Markdown("### FX Levels")
|
| 90 |
+
bright_sl = gr.Slider(0, 10, value=5, label="Brightness (EQ)")
|
| 91 |
+
loud_sl = gr.Slider(0, 10, value=5, label="Loudness (Limiters)")
|
| 92 |
+
verb_sl = gr.Slider(0, 10, value=2, label="Space (Reverb)")
|
| 93 |
+
|
| 94 |
+
with gr.Accordion("Advanced Engine Settings", open=False):
|
| 95 |
+
m_steps = gr.Slider(10, 50, value=25, step=1, label="Refinement Steps")
|
| 96 |
+
m_cfg = gr.Slider(1.0, 15.0, value=3.5, step=0.5, label="AI Guidance Scale")
|
| 97 |
|
| 98 |
+
status = gr.Markdown("Ready.")
|
| 99 |
+
with gr.Row():
|
| 100 |
+
monitor = gr.Audio(label="Studio Monitor")
|
| 101 |
+
export_wav = gr.File(label="Download Master")
|
| 102 |
|
| 103 |
+
# TAB 2: ARTWORK
|
| 104 |
+
with gr.TabItem("π¨ Art Direction"):
|
| 105 |
+
with gr.Row():
|
| 106 |
+
with gr.Column():
|
| 107 |
+
vibe_in = gr.Textbox(label="Visual Theme", placeholder="e.g. Neon Cyberpunk, 70s Vinyl...")
|
| 108 |
+
art_btn = gr.Button("π¨ GENERATE ART")
|
| 109 |
+
|
| 110 |
+
gr.Markdown("### Image 'Levels'")
|
| 111 |
+
art_steps = gr.Slider(1, 4, value=4, step=1, label="Detail Iterations")
|
| 112 |
+
art_cfg = gr.Slider(0.0, 5.0, value=3.5, label="Prompt Strictness")
|
| 113 |
+
|
| 114 |
+
art_out = gr.Image(label="Cover Art")
|
| 115 |
|
| 116 |
+
# TAB 3: PROMO EXPORT
|
| 117 |
+
with gr.TabItem("π¬ Video Export"):
|
| 118 |
+
with gr.Row():
|
| 119 |
+
with gr.Column():
|
| 120 |
+
vol_sl = gr.Slider(0.0, 2.0, value=1.0, label="Final Video Volume (Gain)")
|
| 121 |
+
promo_btn = gr.Button("π¬ RENDER TIKTOK CLIP", variant="primary")
|
| 122 |
+
video_out = gr.Video(label="9:16 Social Preview")
|
| 123 |
+
|
| 124 |
+
# --- WIRING ---
|
| 125 |
+
master_btn.click(
|
| 126 |
+
master_logic,
|
| 127 |
+
[in_audio, bright_sl, loud_sl, verb_sl, m_steps, m_cfg],
|
| 128 |
+
[monitor, export_wav, status, master_storage]
|
| 129 |
+
).then(lambda x: x, in_audio, raw_storage)
|
| 130 |
+
|
| 131 |
+
art_btn.click(art_logic, [status, vibe_in, art_steps, art_cfg], art_out)
|
| 132 |
+
|
| 133 |
+
promo_btn.click(video_logic, [master_storage, art_out, vol_sl], video_out)
|
| 134 |
|
| 135 |
+
demo.launch()
|
|
|