Spaces:
Sleeping
Sleeping
Update app.py
Browse filestrying to fix json extraction
app.py
CHANGED
|
@@ -66,14 +66,15 @@ def get_melody_from_intent(intent, model_name):
|
|
| 66 |
"""
|
| 67 |
response = query_llm(melody_prompt, model_name)
|
| 68 |
print(f"\n[DEBUG] LLM Response for melody:\n{response}\n")
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
print("[WARNING] Using fallback melody.")
|
| 79 |
return [
|
|
|
|
| 66 |
"""
|
| 67 |
response = query_llm(melody_prompt, model_name)
|
| 68 |
print(f"\n[DEBUG] LLM Response for melody:\n{response}\n")
|
| 69 |
+
|
| 70 |
+
try:
|
| 71 |
+
json_strs = re.findall(r'\[\s*\{[^]]+\}\s*\]', response, re.DOTALL)
|
| 72 |
+
for js in json_strs:
|
| 73 |
+
parsed = json.loads(js)
|
| 74 |
+
if isinstance(parsed, list) and all("note" in note and "octave" in note and "duration" in note for note in parsed):
|
| 75 |
+
return parsed
|
| 76 |
+
except json.JSONDecodeError as e:
|
| 77 |
+
print(f"[ERROR] Melody JSON decode error: {e}")
|
| 78 |
|
| 79 |
print("[WARNING] Using fallback melody.")
|
| 80 |
return [
|