Spaces:
Sleeping
Sleeping
SP3 generative song cards
Browse files494 unmodified lines49549649749849950070 unmodified lines571572573574575576494 unmodified linesreturn _pick(content.STATION_IDS) # station_id (default)_FRAGMENT_FLAVORS = ["dedication", "numbers_weather", "station_id", "dream", "song_title"]_FRAGMENT_HINT = {"dedication": "a half-heard dedication to someone you will never name",70 unmodified lines" A listener, %s, sent this one in -- give them a warm little shout ""as you bring it in." % rb)elif kind == "local_weather":user = _local_weather_user(ctx)else:494 unmodified lines49549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658770 unmodified lines658659660661662663664665666494 unmodified linesreturn _pick(content.STATION_IDS) # station_id (default)# ---------------------------------------------------------------------------# Generative song cards (SP3): model writes title+artist; server picks the vibe# and assigns ALWAYS-VALID musical params so a card can never break the engine.# ---------------------------------------------------------------------------_VIBE_MUSIC = {"melancholy": ("minor", "rhodes", 70, ("A", "E", "D")),"lonely": ("minor", "music_box", 64, ("A", "E", "Bb")),"tender": ("major", "music_box", 68, ("C", "F", "Bb")),"warm": ("major", "rhodes", 78, ("C", "D", "G")),"cozy": ("major", "rhodes", 80, ("F", "C", "Bb")),"hopeful": ("lydian", "soft_saw", 80, ("D", "G", "C")),"nostalgic": ("major", "triangle_pluck", 74, ("C", "Bb", "G")),"wistful": ("dorian", "sine_pad", 72, ("C", "D", "F")),"bittersweet": ("minor", "rhodes", 70, ("Bb", "A", "E")),"jazzy": ("dorian", "rhodes", 84, ("D", "F", "G")),"dreamy": ("lydian", "sine_pad", 64, ("F", "D", "Eb")),"pensive": ("dorian", "sine_pad", 76, ("C", "E", "G")),"hypnotic": ("pentatonic_minor", "soft_saw", 70, ("G", "A", "D")),"mysterious": ("lydian", "sine_pad", 68, ("Eb", "A", "F")),"eerie": ("pentatonic_minor", "sine_pad", 60, ("A", "Eb", "G")),"ambient": ("lydian", "sine_pad", 64, ("F", "D", "C")),"romantic": ("minor", "rhodes", 66, ("Ab", "D", "A")),"gentle": ("major", "triangle_pluck", 75, ("C", "G", "D")),"breezy": ("major", "triangle_pluck", 88, ("G", "D", "C")),}_DEFAULT_MUSIC = ("major", "rhodes", 74, ("C", "D", "G"))_MOOD_TO_VIBE = {"warm": "warm", "nostalgic": "nostalgic", "tender": "tender","searching": "pensive", "hollow": "lonely", "uneasy": "eerie",}def _parse_title_artist(text):t = re.sub(r"\s+", " ", text or "").strip().strip("\"'")t = re.sub(r"^(?:title|song)\s*[:=]\s*", "", t, flags=re.IGNORECASE)parts = re.split(r"\s+by\s+", t, maxsplit=1, flags=re.IGNORECASE)if len(parts) != 2:return None, Nonetitle = parts[0].strip().strip("\"'")[:42]# Drop trailing model chatter ("... by The Velvet Sundays. Hope you enjoy!")# at the first real sentence break -- a period after >=4 letters then space --# so abbreviations like "St. Vincent" survive.artist = re.split(r"(?<=[A-Za-z]{4})\.\s", parts[1].strip().strip("\"'"), maxsplit=1)[0].strip()[:42]if 2 <= len(title) <= 42 and 2 <= len(artist) <= 42 and not any(c in t for c in "<>{}[]") and ":" not in title:return title, artistreturn None, Nonedef _procedural_title():return "%s %s" % (random.choice(content.CARD_TITLE_A), random.choice(content.CARD_TITLE_B))def _procedural_artist():return "%s %s" % (random.choice(content.CARD_ARTIST_A), random.choice(content.CARD_ARTIST_B))def _generate_title_artist(ctx, vibe):try:flavor = ""if ctx.get("topic"):flavor = " inspired by someone who said: %s" % str(ctx["topic"])[:80]elif ctx.get("city"):flavor = " for a night in %s" % ctx["city"]user = ("Invent a fictional late-night record with a %s feeling%s. Reply with ONLY ""the song title and the artist in the form: <title> by <artist>." % (vibe, flavor))brain = call_brain(arc.build_song_card_prompt(), [{"role": "user", "content": user}])title, artist = _parse_title_artist(brain.get("text", ""))if title and artist:return title, artistexcept Exception:passreturn _procedural_title(), _procedural_artist()def make_song_card(ctx=None):"""Invent ONE fictional record. Musical params are always valid engine enums."""ctx = ctx or {}vibe = _MOOD_TO_VIBE.get(ctx.get("mood")) or random.choice(list(_VIBE_MUSIC.keys()))scale, timbre, tempo, keys = _VIBE_MUSIC.get(vibe, _DEFAULT_MUSIC)title, artist = _generate_title_artist(ctx, vibe)return {"title": title, "artist": artist, "vibe": vibe,"key": random.choice(keys), "scale": scale, "tempo": tempo, "timbre": timbre,"recommended_by": None, "generated": True,}_FRAGMENT_FLAVORS = ["dedication", "numbers_weather", "station_id", "dream", "song_title"]_FRAGMENT_HINT = {"dedication": "a half-heard dedication to someone you will never name",70 unmodified lines" A listener, %s, sent this one in -- give them a warm little shout ""as you bring it in." % rb)if ctx.get("fresh"):user += (" Mention warmly that this record is brand new -- pressed just ""tonight, never heard before.")elif kind == "local_weather":user = _local_weather_user(ctx)else:
proxy.py+90