Add toggle for automatic MusicGPT polling in settings
This commit is contained in:
parent
77cd712f10
commit
2ec73dee0f
3 changed files with 46 additions and 3 deletions
22
app.py
22
app.py
|
|
@ -58,6 +58,7 @@ from helpers import (
|
||||||
get_max_revisions, get_callback_expiry_hours,
|
get_max_revisions, get_callback_expiry_hours,
|
||||||
get_hermes_api_key, set_hermes_api_key, generate_hermes_api_key, mask_api_key,
|
get_hermes_api_key, set_hermes_api_key, generate_hermes_api_key, mask_api_key,
|
||||||
get_musicgpt_api_key, get_musicgpt_default_model, get_musicgpt_models,
|
get_musicgpt_api_key, get_musicgpt_default_model, get_musicgpt_models,
|
||||||
|
get_musicgpt_autopoll_enabled, set_musicgpt_autopoll_enabled,
|
||||||
build_musicgpt_webhook_url,
|
build_musicgpt_webhook_url,
|
||||||
musicgpt_generate_request, musicgpt_queue_stems, musicgpt_poll_status,
|
musicgpt_generate_request, musicgpt_queue_stems, musicgpt_poll_status,
|
||||||
download_musicgpt_outputs, format_musicgpt_cost, get_musicgpt_cost_totals,
|
download_musicgpt_outputs, format_musicgpt_cost, get_musicgpt_cost_totals,
|
||||||
|
|
@ -378,6 +379,17 @@ def musicgpt_webhook():
|
||||||
return jsonify({'ok': False, 'reason': 'unknown_conversion_type'}), 400
|
return jsonify({'ok': False, 'reason': 'unknown_conversion_type'}), 400
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/admin/musicgpt/autopoll', methods=['POST'])
|
||||||
|
def admin_musicgpt_autopoll():
|
||||||
|
"""Internal endpoint used by the cron job. Only runs refresh if auto-poll is enabled."""
|
||||||
|
redir = require_admin()
|
||||||
|
if redir:
|
||||||
|
return redir
|
||||||
|
if not get_musicgpt_autopoll_enabled():
|
||||||
|
return jsonify({'ok': True, 'autopoll': False, 'message': 'Automatic polling is disabled in settings.'}), 200
|
||||||
|
return admin_musicgpt_refresh()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin/musicgpt/refresh', methods=['POST'])
|
@app.route('/admin/musicgpt/refresh', methods=['POST'])
|
||||||
def admin_musicgpt_refresh():
|
def admin_musicgpt_refresh():
|
||||||
"""Manual dashboard action: poll all in-flight MusicGPT tasks and update statuses."""
|
"""Manual dashboard action: poll all in-flight MusicGPT tasks and update statuses."""
|
||||||
|
|
@ -1273,6 +1285,7 @@ def admin_settings():
|
||||||
current_max_revisions = get_max_revisions()
|
current_max_revisions = get_max_revisions()
|
||||||
current_refresh_seconds = runtime_settings.get('refresh_seconds', 10)
|
current_refresh_seconds = runtime_settings.get('refresh_seconds', 10)
|
||||||
booth_open = runtime_settings.get('booth_open', True)
|
booth_open = runtime_settings.get('booth_open', True)
|
||||||
|
musicgpt_autopoll = runtime_settings.get('musicgpt_autopoll', True)
|
||||||
|
|
||||||
# Effective email config to show in the form (non-sensitive only; password left blank).
|
# Effective email config to show in the form (non-sensitive only; password left blank).
|
||||||
email_form = {
|
email_form = {
|
||||||
|
|
@ -1579,6 +1592,14 @@ def admin_settings():
|
||||||
flash('Album cover delivery setting saved.', 'success')
|
flash('Album cover delivery setting saved.', 'success')
|
||||||
return redirect(url_for('admin_settings'))
|
return redirect(url_for('admin_settings'))
|
||||||
|
|
||||||
|
elif action == 'save_musicgpt_autopoll':
|
||||||
|
cfg = load_booth_settings()
|
||||||
|
cfg['musicgpt_autopoll'] = request.form.get('musicgpt_autopoll', '0') == '1'
|
||||||
|
save_booth_settings(cfg)
|
||||||
|
state = 'enabled' if cfg['musicgpt_autopoll'] else 'disabled'
|
||||||
|
flash(f'Automatic MusicGPT polling {state}.', 'success')
|
||||||
|
return redirect(url_for('admin_settings'))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'admin/settings.html',
|
'admin/settings.html',
|
||||||
health=health,
|
health=health,
|
||||||
|
|
@ -1611,6 +1632,7 @@ def admin_settings():
|
||||||
deliver_album_cover=runtime_settings.get('deliver_album_cover', False),
|
deliver_album_cover=runtime_settings.get('deliver_album_cover', False),
|
||||||
musicgpt_api_key_set=bool(get_musicgpt_api_key()),
|
musicgpt_api_key_set=bool(get_musicgpt_api_key()),
|
||||||
musicgpt_webhook_url=build_musicgpt_webhook_url(),
|
musicgpt_webhook_url=build_musicgpt_webhook_url(),
|
||||||
|
musicgpt_autopoll=runtime_settings.get('musicgpt_autopoll', True),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
14
helpers.py
14
helpers.py
|
|
@ -527,9 +527,17 @@ def get_booth_open():
|
||||||
return cfg.get('booth_open', True)
|
return cfg.get('booth_open', True)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
def get_musicgpt_autopoll_enabled():
|
||||||
# MusicGPT API client
|
"""Return True if automatic MusicGPT polling is enabled (default True)."""
|
||||||
# ---------------------------------------------------------------------------
|
cfg = load_booth_settings()
|
||||||
|
return cfg.get('musicgpt_autopoll', True)
|
||||||
|
|
||||||
|
|
||||||
|
def set_musicgpt_autopoll_enabled(enabled):
|
||||||
|
"""Persist the automatic MusicGPT polling toggle."""
|
||||||
|
cfg = load_booth_settings()
|
||||||
|
cfg['musicgpt_autopoll'] = bool(enabled)
|
||||||
|
save_booth_settings(cfg)
|
||||||
|
|
||||||
MUSICGPT_API_BASE = "https://api.musicgpt.com/api/public"
|
MUSICGPT_API_BASE = "https://api.musicgpt.com/api/public"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,19 @@
|
||||||
</label>
|
</label>
|
||||||
<button type="submit">Save Album Cover Setting</button>
|
<button type="submit">Save Album Cover Setting</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<hr style="border:none;border-top:1px solid var(--border);margin:1.5rem 0;">
|
||||||
|
|
||||||
|
<h3>Automatic MusicGPT Polling</h3>
|
||||||
|
<p class="copy-hint">When enabled, the site automatically polls MusicGPT every few minutes and downloads MP3/WAV files once they are ready.</p>
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="action" value="save_musicgpt_autopoll">
|
||||||
|
<label for="musicgpt_autopoll" style="display:flex;align-items:center;gap:.5rem;cursor:pointer;">
|
||||||
|
<input type="checkbox" id="musicgpt_autopoll" name="musicgpt_autopoll" value="1" {% if musicgpt_autopoll %}checked{% endif %} style="width:auto;margin:0">
|
||||||
|
Enable automatic MusicGPT polling
|
||||||
|
</label>
|
||||||
|
<button type="submit">Save Auto-Poll Setting</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Email / SMTP configuration -->
|
<!-- Email / SMTP configuration -->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue