matthewbarberdev commited on
Commit
3b7b9f0
·
verified ·
1 Parent(s): 8c1332e

Update app.py

Browse files

trying to fix json extraction

Files changed (1) hide show
  1. app.py +9 -8
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
- match = re.search(r'\[.*\]', response, re.DOTALL)
70
- if match:
71
- try:
72
- melody = json.loads(match.group(0))
73
- if isinstance(melody, list) and len(melody) > 0:
74
- return melody
75
- except json.JSONDecodeError as e:
76
- print(f"[ERROR] Melody JSON decode error: {e}")
 
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 [