Curlyblaze commited on
Commit
34b3e94
Β·
verified Β·
1 Parent(s): 33c6c4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -44
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
- def master_logic(audio_path):
13
- if not audio_path: return None, None, "Upload a track!", None
 
 
 
 
14
  results = classifier(audio_path)
15
  genre = results[0]['label']
16
 
17
- # API call: returns [audio_file, status_text]
 
 
 
 
 
 
 
18
  result = mastering_client.predict(
19
  handle_file(audio_path),
20
- f"Professional {genre} studio master.",
21
- 42, 25, 3.5
 
 
22
  )
23
 
24
- # USE result[0] for the actual file
25
- mastered_file = result[0]
26
- return mastered_file, mastered_file, f"Genre: **{genre}** | Mastered ✨", mastered_file
 
27
 
28
- def art_logic(status_text, vibe):
29
  if not status_text or "Ready" in status_text: return None
30
- clean_genre = status_text.split("**")[1] if "**" in status_text else "Music"
 
 
31
 
32
  img_result = image_client.predict(
33
- prompt=f"Professional album cover, {clean_genre}, {vibe}, high res",
34
- seed=0, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=4,
 
 
 
 
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
- audio = AudioFileClip(audio_path).subclipped(0, 30)
 
 
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
- video.write_videofile("promo.mp4", fps=24, codec="libx264")
45
- return "promo.mp4"
46
-
47
- def toggle_ab(choice, raw, mastered):
48
- return mastered if "Mastered" in choice else raw
49
 
50
- # --- UI ---
51
- with gr.Blocks() as demo:
52
- gr.Markdown("# 🎡 AI Artist Studio")
 
53
  raw_storage = gr.State()
54
  master_storage = gr.State()
55
 
56
  with gr.Tabs():
57
- with gr.TabItem("🎧 1. Master"):
58
- in_audio = gr.Audio(label="Upload", type="filepath")
59
- master_btn = gr.Button("πŸš€ MASTER", variant="primary")
60
  with gr.Row():
61
- monitor = gr.Audio(label="Monitor")
62
- ab_toggle = gr.Radio(["Original πŸ”ˆ", "Mastered ✨"], value="Mastered ✨", label="A/B")
63
- status = gr.Markdown("Ready")
64
- export_file = gr.File(label="WAV")
 
 
 
 
 
 
 
 
 
65
 
66
- with gr.TabItem("🎨 2. Art"):
67
- vibe_in = gr.Textbox(label="Vibe")
68
- art_btn = gr.Button("🎨 ART")
69
- art_out = gr.Image()
70
 
71
- with gr.TabItem("πŸ“± 3. Promo"):
72
- promo_btn = gr.Button("🎬 VIDEO")
73
- video_out = gr.Video()
 
 
 
 
 
 
 
 
 
74
 
75
- master_btn.click(master_logic, in_audio, [monitor, export_file, status, master_storage]).then(
76
- lambda x: x, in_audio, raw_storage
77
- )
78
- ab_toggle.change(toggle_ab, [ab_toggle, raw_storage, master_storage], monitor)
79
- art_btn.click(art_logic, [status, vibe_in], art_out)
80
- promo_btn.click(video_logic, [master_storage, art_out], video_out)
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- # Theme moved to launch to fix the UserWarning
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()