Spaces:
Running
Running
Download studio/remix.py from 2Btainment/2b-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.83 kB
-
https://huggingface.co/spaces/2Btainment/2b-studio/resolve/main/studio/remix.py
- Command line
-
hf download hf://spaces/2Btainment/2b-studio/studio/remix.py
-
curl -L -o remix.py https://huggingface.co/spaces/2Btainment/2b-studio/resolve/main/studio/remix.py
2.83 kB
| from __future__ import annotations | |
| from pydantic import BaseModel | |
| from studio.audio_analysis import AudioAnalysis | |
| from studio.state import Track | |
| class RemixPlan(BaseModel): | |
| model_id: str | |
| genre_style_instruments: str | |
| lyrics: str | |
| negative: str | |
| duration_s: int | |
| rationale: str | |
| summary: str = "" | |
| def _join_unique(*values: str) -> str: | |
| parts: list[str] = [] | |
| seen: set[str] = set() | |
| for value in values: | |
| for part in (item.strip() for item in value.replace(" · ", ",").split(",")): | |
| if part and part.casefold() not in seen: | |
| parts.append(part) | |
| seen.add(part.casefold()) | |
| return ", ".join(parts) | |
| def build_remix_plan(track: Track, analysis: AudioAnalysis) -> RemixPlan: | |
| metadata = track.metadata | |
| source_prompt = str(metadata.get("genre_style_instruments", "")).strip() | |
| source_lyrics = str(metadata.get("lyrics", "[Instrumental]")).strip() or "[Instrumental]" | |
| source_negative = str(metadata.get("negative", "")).strip() | |
| model_id = str(metadata.get("model_id", "minimax-music3")) | |
| character_prompt = ( | |
| f"reference-aware remix, preserve the core melodic and rhythmic identity, " | |
| f"{analysis.character}, refined arrangement, intentional transitions, " | |
| "high-definition production, controlled depth, memorable focal hook" | |
| ) | |
| corrective_terms = [ | |
| "uncontrolled clipping", | |
| "phase cancellation", | |
| "muddy low mids", | |
| "generic AI artifacts", | |
| "unfocused arrangement", | |
| ] | |
| if analysis.peak_dbfs > -1.0: | |
| corrective_terms.append("over-limited transients") | |
| if analysis.zero_crossing_rate > 0.14: | |
| corrective_terms.append("brittle high-frequency noise") | |
| if analysis.crest_db < 7: | |
| corrective_terms.append("lifeless microdynamics") | |
| return RemixPlan( | |
| model_id=model_id, | |
| genre_style_instruments=_join_unique(source_prompt, character_prompt), | |
| lyrics=source_lyrics, | |
| negative=_join_unique(source_negative, ", ".join(corrective_terms)), | |
| duration_s=max(5, min(30, round(analysis.duration_s))), | |
| rationale=( | |
| f"Referenz analysiert: {analysis.character}; RMS {analysis.rms_dbfs:.1f} dBFS, " | |
| f"Crest {analysis.crest_db:.1f} dB. Identität bleibt erhalten, technische " | |
| "Schwächen werden als Negativregeln zurückgeführt." | |
| ), | |
| summary=( | |
| f"Der Track wurde als {analysis.character} eingestuft. Smart Remix behält " | |
| "Melodie, Rhythmus und Stil bei, verfeinert das Arrangement und ergänzt " | |
| f"{len(corrective_terms)} Negativregeln gegen technische Schwächen. " | |
| "Der Seed wird aus dem Referenztrack abgeleitet – gleiche Referenz, " | |
| "gleiches Ergebnis." | |
| ), | |
| ) | |