Fix MusicGPT integration: v6/v6-pro models, per-conversion webhooks, store conversion IDs
This commit is contained in:
parent
f185232907
commit
5443c464bd
5 changed files with 81 additions and 43 deletions
43
app.py
43
app.py
|
|
@ -297,30 +297,43 @@ def musicgpt_webhook():
|
|||
return jsonify({'ok': False, 'reason': 'missing_task_id'}), 400
|
||||
|
||||
conversion_id = data.get('conversion_id')
|
||||
if not conversion_id and 'conversion_id_1' in data:
|
||||
conversion_id = data.get('conversion_id_1')
|
||||
|
||||
# Music AI generation webhook
|
||||
if 'Music' in conversion_type or 'Music AI' in conversion_type:
|
||||
req = None
|
||||
if 'Music' in conversion_type or 'Music AI' in conversion_type or not conversion_type:
|
||||
db = get_db()
|
||||
row = db.execute('SELECT * FROM requests WHERE musicgpt_task_id = ?', (task_id,)).fetchone()
|
||||
if row:
|
||||
req = dict(row)
|
||||
if not req:
|
||||
if not row:
|
||||
return jsonify({'ok': False, 'reason': 'request_not_found'}), 404
|
||||
req = dict(row)
|
||||
|
||||
# Determine which version this webhook belongs to.
|
||||
version = None
|
||||
if req.get('musicgpt_conversion_id_1') and conversion_id == req['musicgpt_conversion_id_1']:
|
||||
version = 'A'
|
||||
elif req.get('musicgpt_conversion_id_2') and conversion_id == req['musicgpt_conversion_id_2']:
|
||||
version = 'B'
|
||||
else:
|
||||
# Fallback: if only one conversion_id stored, or single-webhook payload.
|
||||
if not req.get('musicgpt_conversion_id_1'):
|
||||
version = 'A'
|
||||
elif not req.get('musicgpt_conversion_id_2'):
|
||||
version = 'B'
|
||||
|
||||
new_status = status.upper()
|
||||
update_fields = {'musicgpt_status': new_status}
|
||||
if data.get('is_flagged'):
|
||||
update_fields['musicgpt_error'] = data.get('reason') or 'Flagged by MusicGPT'
|
||||
if new_status in ('COMPLETED', 'FINISHED'):
|
||||
download_musicgpt_outputs(req, data)
|
||||
download_musicgpt_outputs(req, data, version=version)
|
||||
# Re-fetch to get updated paths.
|
||||
row = db.execute('SELECT * FROM requests WHERE id = ?', (req['id'],)).fetchone()
|
||||
req = dict(row)
|
||||
if req.get('song_a_path') and req.get('song_b_path'):
|
||||
update_fields['status'] = 'songs_uploaded'
|
||||
try:
|
||||
update_fields['musicgpt_cost'] = float(data.get('conversion_cost') or 0)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
elif new_status in ('FAILED', 'ERROR'):
|
||||
update_fields['musicgpt_error'] = data.get('reason') or data.get('error') or 'MusicGPT reported failure'
|
||||
update_request(req['id'], **update_fields)
|
||||
|
|
@ -328,13 +341,11 @@ def musicgpt_webhook():
|
|||
|
||||
# Extraction / stems webhook
|
||||
if 'Extraction' in conversion_type:
|
||||
req = None
|
||||
db = get_db()
|
||||
row = db.execute('SELECT * FROM requests WHERE stems_task_id = ?', (task_id,)).fetchone()
|
||||
if row:
|
||||
req = dict(row)
|
||||
if not req:
|
||||
if not row:
|
||||
return jsonify({'ok': False, 'reason': 'request_not_found'}), 404
|
||||
req = dict(row)
|
||||
|
||||
new_status = status.upper()
|
||||
update_fields = {'stems_status': new_status}
|
||||
|
|
@ -902,7 +913,8 @@ def admin_request(rid):
|
|||
rid, title, style, lyrics, gender=gender, model=model
|
||||
)
|
||||
if error:
|
||||
update_request(rid, musicgpt_status='ERROR', musicgpt_error=error)
|
||||
update_request(rid, musicgpt_status='ERROR', musicgpt_error=error,
|
||||
musicgpt_conversion_id_1=conv1, musicgpt_conversion_id_2=conv2)
|
||||
flash(f'Failed to queue MusicGPT generation: {error}', 'error')
|
||||
else:
|
||||
update_request(rid,
|
||||
|
|
@ -910,6 +922,8 @@ def admin_request(rid):
|
|||
suno_style=style,
|
||||
suno_lyrics=lyrics,
|
||||
musicgpt_task_id=task_id,
|
||||
musicgpt_conversion_id_1=conv1,
|
||||
musicgpt_conversion_id_2=conv2,
|
||||
musicgpt_status='IN_QUEUE',
|
||||
musicgpt_error=None,
|
||||
musicgpt_cost=estimate,
|
||||
|
|
@ -1262,7 +1276,8 @@ def admin_settings():
|
|||
'suno_lyrics', 'song_a_path', 'song_b_path', 'customer_approved',
|
||||
'approval_notified_at', 'preview_sent_at', 'delivery_sent_at',
|
||||
'square_payment_ref', 'admin_alert_email', 'player_token', 'revision_note', 'revision_count', 'operator_notes', 'stems_link', 'stems_interest',
|
||||
'musicgpt_task_id', 'musicgpt_status', 'musicgpt_cost', 'musicgpt_error',
|
||||
'musicgpt_task_id', 'musicgpt_conversion_id_1', 'musicgpt_conversion_id_2',
|
||||
'musicgpt_status', 'musicgpt_cost', 'musicgpt_error',
|
||||
'album_cover_url', 'song_a_wav_path', 'song_b_wav_path', 'deliver_wav',
|
||||
'stems_task_id', 'stems_status', 'stems_cost', 'stems_url', 'stems_error'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue