Refine music prompt generation in app.py. Updated the ENRICH_SYSTEM to clarify JSON response structure and enhance music_prompt template with specific instrument and background noise guidelines. Adjusted temperature setting for improved output consistency and ensured background noise is always included in the music prompt.
Browse files
app.py
CHANGED
|
@@ -46,19 +46,28 @@ app = Server(title="LoFinity")
|
|
| 46 |
|
| 47 |
ENRICH_SYSTEM = """\
|
| 48 |
You are the creative brain of LoFinity, a magical vending machine that sells
|
| 49 |
-
lofi cassette tapes. The user
|
| 50 |
-
{"music_prompt": "...", "title": "..."}
|
| 51 |
|
| 52 |
-
music_prompt
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
(
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
title: a cozy cassette tape title inspired by the vibe, max 5 words,
|
| 61 |
-
Title Case, no quotes or emoji.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
def enrich_prompt(prompt: str) -> tuple[str, str]:
|
|
@@ -75,7 +84,7 @@ def enrich_prompt(prompt: str) -> tuple[str, str]:
|
|
| 75 |
],
|
| 76 |
"format": "json",
|
| 77 |
"stream": False,
|
| 78 |
-
"options": {"temperature": 0.
|
| 79 |
},
|
| 80 |
timeout=45,
|
| 81 |
)
|
|
@@ -87,6 +96,13 @@ def enrich_prompt(prompt: str) -> tuple[str, str]:
|
|
| 87 |
# belt and suspenders: the genre must lead even if the LLM drifts
|
| 88 |
if "lofi" not in music_prompt.lower():
|
| 89 |
music_prompt = f"lofi chill, {music_prompt}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
return music_prompt, title
|
| 91 |
except Exception as e: # noqa: BLE001 — any failure means "use fallback"
|
| 92 |
print(f"[lofinity] ollama enrichment failed ({e!r}), using fallback")
|
|
|
|
| 46 |
|
| 47 |
ENRICH_SYSTEM = """\
|
| 48 |
You are the creative brain of LoFinity, a magical vending machine that sells
|
| 49 |
+
lofi cassette tapes. The user gives you a vibe. Reply ONLY with JSON with
|
| 50 |
+
exactly these two keys: {"music_prompt": "...", "title": "..."}
|
| 51 |
|
| 52 |
+
Build music_prompt from this template, in this order:
|
| 53 |
+
"lofi chill, <instrument 1>, <instrument 2>, <instrument 3>, <background noise>, <mood>, slow tempo, 75 bpm, instrumental"
|
| 54 |
+
|
| 55 |
+
- instruments: 2-3 picked to EVOKE the user's vibe, never a default set
|
| 56 |
+
(island -> ukulele, kalimba, steel pan; rainy city -> rhodes piano, soft
|
| 57 |
+
guitar; winter -> felt piano, soft strings; desert -> slide guitar, hand drums)
|
| 58 |
+
- background noise: exactly one, matched to the vibe: vinyl crackle, tape
|
| 59 |
+
hiss, soft rain, ocean waves, fireplace crackle, birdsong, night crickets,
|
| 60 |
+
cafe murmur, or wind in trees
|
| 61 |
+
- mood: one or two calm words; never energetic, no vocals
|
| 62 |
|
| 63 |
title: a cozy cassette tape title inspired by the vibe, max 5 words,
|
| 64 |
+
Title Case, no quotes or emoji.
|
| 65 |
+
|
| 66 |
+
Examples:
|
| 67 |
+
user: island summer
|
| 68 |
+
{"music_prompt": "lofi chill, ukulele, kalimba, steel pan, ocean waves in the background, breezy and warm, slow tempo, 75 bpm, instrumental", "title": "Coconut Daydream"}
|
| 69 |
+
user: studying at midnight
|
| 70 |
+
{"music_prompt": "lofi chill, rhodes piano, muted guitar, soft bass, vinyl crackle in the background, focused and calm, slow tempo, 75 bpm, instrumental", "title": "Midnight Study Session"}"""
|
| 71 |
|
| 72 |
|
| 73 |
def enrich_prompt(prompt: str) -> tuple[str, str]:
|
|
|
|
| 84 |
],
|
| 85 |
"format": "json",
|
| 86 |
"stream": False,
|
| 87 |
+
"options": {"temperature": 0.8, "num_predict": 220},
|
| 88 |
},
|
| 89 |
timeout=45,
|
| 90 |
)
|
|
|
|
| 96 |
# belt and suspenders: the genre must lead even if the LLM drifts
|
| 97 |
if "lofi" not in music_prompt.lower():
|
| 98 |
music_prompt = f"lofi chill, {music_prompt}"
|
| 99 |
+
# …and there must always be a background noise layer
|
| 100 |
+
noise_words = (
|
| 101 |
+
"crackle", "hiss", "rain", "waves", "noise", "birdsong",
|
| 102 |
+
"crickets", "murmur", "wind", "fireplace", "static",
|
| 103 |
+
)
|
| 104 |
+
if not any(w in music_prompt.lower() for w in noise_words):
|
| 105 |
+
music_prompt += ", soft vinyl crackle in the background"
|
| 106 |
return music_prompt, title
|
| 107 |
except Exception as e: # noqa: BLE001 — any failure means "use fallback"
|
| 108 |
print(f"[lofinity] ollama enrichment failed ({e!r}), using fallback")
|