Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Account: every usage limit in one card, balanced layout (#413)

Murtaza Nasirdedeeecbf059
diff --git a/src/api/auth.py b/src/api/auth.py
index bea56815..e0f7ac71 100644
--- a/src/api/auth.py
+++ b/src/api/auth.py
@@ -623,6 +623,39 @@ def _storage_usage(user):
return None
+def _usage_limits(user):
+ """AI tokens and transcription minutes this month, and storage, each
+ against its limit when one is set, for the Account page (#413)."""
+ def size(n):
+ return f"{n / 1073741824:.1f} GB" if n >= 1073741824 else f"{n / 1048576:.1f} MB"
+
+ def row(key, label_key, icon, used, limit, fmt):
+ pct = round(used / limit * 100, 1) if limit else None
+ return {'key': key, 'label_key': label_key, 'icon': icon, 'used': fmt(used),
+ 'limit': fmt(limit) if limit else None, 'percentage': pct}
+
+ rows = []
+ try:
+ from src.services.token_tracking import token_tracker
+ rows.append(row('tokens', 'account.aiTokensMonth', 'fa-coins',
+ int(token_tracker.get_monthly_usage(user.id) or 0), user.monthly_token_budget,
+ lambda n: f"{int(n):,}"))
+ except Exception as e:
+ current_app.logger.warning(f"Could not read token usage for user {user.id}: {e}")
+ try:
+ from src.services.transcription_tracking import transcription_tracker
+ seconds = int(transcription_tracker.get_monthly_usage(user.id) or 0)
+ budget = user.monthly_transcription_budget
+ rows.append(row('transcription', 'account.transcriptionMonth', 'fa-microphone',
+ seconds // 60, (budget // 60) if budget else None, lambda n: f"{int(n):,} min"))
+ except Exception as e:
+ current_app.logger.warning(f"Could not read transcription usage for user {user.id}: {e}")
+ storage = _storage_usage(user)
+ if storage:
+ rows.append(row('storage', 'account.storage', 'fa-hdd', storage['used_bytes'], storage['quota_bytes'], size))
+ return rows
+
+
@auth_bp.route('/api/account/storage', methods=['GET'])
@login_required
def account_storage():
@@ -880,6 +913,7 @@ def account():
return render_template('account.html',
title='Account',
storage_usage=_storage_usage(current_user),
+ usage_limits=_usage_limits(current_user),
default_summary_prompt_text=default_summary_prompt_text,
default_title_prompt_text=default_title_prompt_text,
use_asr_endpoint=USE_ASR_ENDPOINT,
diff --git a/static/locales/de.json b/static/locales/de.json
index 2f99c309..70afd143 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -116,7 +116,11 @@
"storageOfQuota": "{{used}} von {{quota}}",
"storageNoLimit": "{{used}} belegt, keine Begrenzung",
"storageFull": "Ihr Speicher ist voll. Uploads und neue Aufnahmen werden abgelehnt, bis Sie Aufnahmen löschen oder deren Audio entfernen.",
- "storageHelp": "Zählt das Audio und Video, das Sie behalten. Aufnahmen mit entferntem Audio zählen nicht."
+ "storageHelp": "Zählt das Audio und Video, das Sie behalten. Aufnahmen mit entferntem Audio zählen nicht.",
+ "usageAndLimits": "Nutzung und Limits",
+ "aiTokensMonth": "KI-Tokens diesen Monat",
+ "transcriptionMonth": "Transkription diesen Monat",
+ "usageHelp": "KI-Tokens und Transkriptionsminuten zählen ab Monatsbeginn. Der Speicher zählt das Audio und Video, das Sie behalten; Aufnahmen mit entferntem Audio zählen nicht."
},
"accountTabs": {
"about": "Über",
diff --git a/static/locales/en.json b/static/locales/en.json
index 1a07166a..f76cc862 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -116,7 +116,11 @@
"storageOfQuota": "{{used}} of {{quota}}",
"storageNoLimit": "{{used}} used, no limit",
"storageFull": "Your storage is full. Uploads and new recordings are refused until you delete recordings or remove their audio.",
- "storageHelp": "Counts the audio and video you keep. Recordings with their audio removed do not count."
+ "storageHelp": "Counts the audio and video you keep. Recordings with their audio removed do not count.",
+ "usageAndLimits": "Usage and Limits",
+ "aiTokensMonth": "AI tokens this month",
+ "transcriptionMonth": "Transcription this month",
+ "usageHelp": "AI tokens and transcription minutes count from the start of each month. Storage counts the audio and video you keep; recordings with their audio removed do not count."
},
"accountTabs": {
"about": "About",
diff --git a/static/locales/es.json b/static/locales/es.json
index 545a4e6e..bae839bc 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -116,7 +116,11 @@
"storageOfQuota": "{{used}} de {{quota}}",
"storageNoLimit": "{{used}} usados, sin límite",
"storageFull": "Su almacenamiento está lleno. Las subidas y las grabaciones nuevas se rechazan hasta que elimine grabaciones o quite su audio.",
- "storageHelp": "Cuenta el audio y el vídeo que conserva. Las grabaciones sin audio no cuentan."
+ "storageHelp": "Cuenta el audio y el vídeo que conserva. Las grabaciones sin audio no cuentan.",
+ "usageAndLimits": "Uso y límites",
+ "aiTokensMonth": "Tokens de IA este mes",
+ "transcriptionMonth": "Transcripción este mes",
+ "usageHelp": "Los tokens de IA y los minutos de transcripción cuentan desde el inicio de cada mes. El almacenamiento cuenta el audio y el vídeo que conserva; las grabaciones sin audio no cuentan."
},
"accountTabs": {
"about": "Acerca de",
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 73c71eec..2e6a8bef 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -116,7 +116,11 @@
"storageOfQuota": "{{used}} sur {{quota}}",
"storageNoLimit": "{{used}} utilisés, aucune limite",
"storageFull": "Votre stockage est plein. Les envois et les nouveaux enregistrements sont refusés jusqu'à ce que vous supprimiez des enregistrements ou leur audio.",
- "storageHelp": "Compte l'audio et la vidéo que vous conservez. Les enregistrements dont l'audio a été supprimé ne comptent pas."
+ "storageHelp": "Compte l'audio et la vidéo que vous conservez. Les enregistrements dont l'audio a été supprimé ne comptent pas.",
+ "usageAndLimits": "Utilisation et limites",
+ "aiTokensMonth": "Tokens IA ce mois-ci",
+ "transcriptionMonth": "Transcription ce mois-ci",
+ "usageHelp": "Les tokens IA et les minutes de transcription comptent depuis le début du mois. Le stockage compte l'audio et la vidéo que vous conservez ; les enregistrements dont l'audio a été supprimé ne comptent pas."
},
"accountTabs": {
"about": "À Propos",
diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.json
index 5546d5e5..a50894ea 100644
--- a/static/locales/pt-BR.json
+++ b/static/locales/pt-BR.json
@@ -116,7 +116,11 @@
"storageOfQuota": "{{used}} de {{quota}}",
"storageNoLimit": "{{used}} usados, sem limite",
"storageFull": "Seu armazenamento está cheio. Envios e novas gravações são recusados até você excluir gravações ou remover o áudio delas.",
- "storageHelp": "Conta o áudio e o vídeo que você mantém. Gravações com o áudio removido não contam."
+ "storageHelp": "Conta o áudio e o vídeo que você mantém. Gravações com o áudio removido não contam.",
+ "usageAndLimits": "Uso e limites",
+ "aiTokensMonth": "Tokens de IA neste mês",
+ "transcriptionMonth": "Transcrição neste mês",
+ "usageHelp": "Tokens de IA e minutos de transcrição contam a partir do início de cada mês. O armazenamento conta o áudio e o vídeo que você mantém; gravações com o áudio removido não contam."
},
"accountTabs": {
"about": "Sobre",
diff --git a/static/locales/ru.json b/static/locales/ru.json
index c36c5fd7..668358ca 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -116,7 +116,11 @@
"storageOfQuota": "{{used}} из {{quota}}",
"storageNoLimit": "Использовано {{used}}, без ограничения",
"storageFull": "Хранилище заполнено. Загрузки и новые записи отклоняются, пока вы не удалите записи или их аудио.",
- "storageHelp": "Учитываются сохранённые аудио и видео. Записи с удалённым аудио не учитываются."
+ "storageHelp": "Учитываются сохранённые аудио и видео. Записи с удалённым аудио не учитываются.",
+ "usageAndLimits": "Использование и лимиты",
+ "aiTokensMonth": "Токены ИИ за месяц",
+ "transcriptionMonth": "Транскрибация за месяц",
+ "usageHelp": "Токены ИИ и минуты транскрибации считаются с начала месяца. Хранилище учитывает сохранённые аудио и видео; записи с удалённым аудио не учитываются."
},
"accountTabs": {
"about": "О продукте",
diff --git a/static/locales/zh.json b/static/locales/zh.json
index 15ed4f07..afac7501 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -116,7 +116,11 @@
"storageOfQuota": "{{used}} / {{quota}}",
"storageNoLimit": "已用 {{used}},不限制",
"storageFull": "您的存储已满。在删除录音或删除其音频之前,上传和新录音都会被拒绝。",
- "storageHelp": "计入您保留的音频和视频。已删除音频的录音不计入。"
+ "storageHelp": "计入您保留的音频和视频。已删除音频的录音不计入。",
+ "usageAndLimits": "用量与限额",
+ "aiTokensMonth": "本月 AI 令牌",
+ "transcriptionMonth": "本月转录",
+ "usageHelp": "AI 令牌和转录分钟数从每月月初开始计算。存储计入您保留的音频和视频;已删除音频的录音不计入。"
},
"accountTabs": {
"about": "关于",
diff --git a/templates/account.html b/templates/account.html
index d18e4c75..bfe131b5 100644
--- a/templates/account.html
+++ b/templates/account.html
@@ -543,42 +543,10 @@
{% endif %}
{% endwith %}
- <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
- <!-- Left Column: Form -->
- <div>
- <form id="accountInfoForm" method="POST" action="{{ url_for('auth.account') }}" class="space-y-6">
- <div class="mb-6">
- <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
- <h3 class="text-lg font-medium text-[var(--text-secondary)] mb-2" data-i18n="account.personalInfo">Personal Information</h3>
- <div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] space-y-4">
- <div>
- <label for="user_name" class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="account.fullName">Full Name</label>
- <input type="text" name="user_name" id="user_name" value="{{ current_user.name or '' }}" data-i18n-placeholder="form.yourFullName" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]">
- </div>
- <div>
- <label for="user_job_title" class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="account.jobTitle">Job Title</label>
- <input type="text" name="user_job_title" id="user_job_title" value="{{ current_user.job_title or '' }}" placeholder="e.g., Software Engineer" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]">
- </div>
- <div>
- <label for="user_company" class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="account.companyOrganization">Company / Organization</label>
- <input type="text" name="user_company" id="user_company" value="{{ current_user.company or '' }}" placeholder="e.g., Acme Corp" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]">
- </div>
- </div>
- </div>
-
- <!-- Save button moved to the sticky tab-footer
- at the bottom of this content area; the
- button there uses form="accountInfoForm"
- to submit this form. -->
- </form>
- </div>
-
- <!-- Right Column: Stats, User Details, Account Actions -->
- <div class="space-y-6">
- <div>
+ <div class="mb-8">
<h3 class="text-lg font-medium text-[var(--text-secondary)] mb-2" data-i18n="account.statistics">Account Statistics</h3>
<div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)]">
- <div class="grid grid-cols-2 gap-4">
+ <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="text-center p-4 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)] shadow-sm">
<span class="block text-3xl font-bold text-[var(--text-accent)]">{{ current_user.recordings|length }}</span>
<span class="block text-sm text-[var(--text-muted)]" data-i18n="account.totalRecordings">Total Recordings</span>
@@ -608,34 +576,37 @@
<span class="block text-sm text-[var(--text-muted)]" data-i18n="account.failedRecordings">Failed</span>
</div>
</div>
- {# Storage used, against the quota when there is one (#413) #}
- {% if storage_usage %}
- {% macro size(n) %}{% if n >= 1073741824 %}{{ '%.1f'|format(n / 1073741824) }} GB{% else %}{{ '%.1f'|format(n / 1048576) }} MB{% endif %}{% endmacro %}
- {% set pct = storage_usage.percentage %}
- <div class="mt-4 p-4 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)] shadow-sm" id="account-storage">
- <div class="flex items-baseline justify-between gap-3 text-sm">
- <span class="font-medium text-[var(--text-secondary)]" data-i18n="account.storage">Storage</span>
- {% if storage_usage.quota_bytes %}
- <span class="text-[var(--text-primary)] tabular-nums" data-i18n="account.storageOfQuota" data-i18n-params='{"used": "{{ size(storage_usage.used_bytes)|trim }}", "quota": "{{ size(storage_usage.quota_bytes)|trim }}"}'>{{ size(storage_usage.used_bytes)|trim }} of {{ size(storage_usage.quota_bytes)|trim }}</span>
- {% else %}
- <span class="text-[var(--text-primary)] tabular-nums" data-i18n="account.storageNoLimit" data-i18n-params='{"used": "{{ size(storage_usage.used_bytes)|trim }}"}'>{{ size(storage_usage.used_bytes)|trim }} used, no limit</span>
- {% endif %}
+ </div>
+ </div>
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
+ <!-- Left Column: personal information, user details -->
+ <div class="space-y-6">
+ <form id="accountInfoForm" method="POST" action="{{ url_for('auth.account') }}" class="space-y-6">
+ <div class="mb-6">
+ <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
+ <h3 class="text-lg font-medium text-[var(--text-secondary)] mb-2" data-i18n="account.personalInfo">Personal Information</h3>
+ <div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] space-y-4">
+ <div>
+ <label for="user_name" class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="account.fullName">Full Name</label>
+ <input type="text" name="user_name" id="user_name" value="{{ current_user.name or '' }}" data-i18n-placeholder="form.yourFullName" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]">
</div>
- {% if storage_usage.quota_bytes %}
- <div class="w-full bg-[var(--bg-tertiary)] rounded-full h-2 mt-2">
- <div class="h-2 rounded-full {% if pct >= 100 %}bg-[var(--text-danger-strong)]{% elif pct >= 80 %}bg-[var(--text-warn-strong)]{% else %}bg-[var(--text-success-strong)]{% endif %}" style="width: {{ [pct, 100]|min }}%"></div>
+ <div>
+ <label for="user_job_title" class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="account.jobTitle">Job Title</label>
+ <input type="text" name="user_job_title" id="user_job_title" value="{{ current_user.job_title or '' }}" placeholder="e.g., Software Engineer" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]">
+ </div>
+ <div>
+ <label for="user_company" class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="account.companyOrganization">Company / Organization</label>
+ <input type="text" name="user_company" id="user_company" value="{{ current_user.company or '' }}" placeholder="e.g., Acme Corp" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]">
</div>
- {% if pct >= 100 %}
- <p class="text-xs text-[var(--text-danger-strong)] mt-2" data-i18n="account.storageFull">Your storage is full. Uploads and new recordings are refused until you delete recordings or remove their audio.</p>
- {% endif %}
- {% endif %}
- <p class="text-xs text-[var(--text-muted)] mt-2" data-i18n="account.storageHelp">Counts the audio and video you keep. Recordings with their audio removed do not count.</p>
</div>
- {% endif %}
</div>
- </div>
- <div class="mt-6"> <!-- Added mt-6 for spacing, was mb-6 on User Details -->
+ <!-- Save button moved to the sticky tab-footer
+ at the bottom of this content area; the
+ button there uses form="accountInfoForm"
+ to submit this form. -->
+ </form>
+ <div>
<h3 class="text-lg font-medium text-[var(--text-secondary)] mb-2" data-i18n="account.userDetails">User Details</h3>
<div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)]">
<div class="mb-3">
@@ -649,13 +620,50 @@
</div>
</div>
+ </div>
+
+ <!-- Right Column: usage and limits, sign-in -->
+ <div class="space-y-6">
+ <!-- Usage and limits: AI tokens and transcription this
+ month, and storage, each against its limit when the
+ administrator set one (#413). -->
+ {% if usage_limits %}
+ <div>
+ <h3 class="text-lg font-medium text-[var(--text-secondary)] mb-2" data-i18n="account.usageAndLimits">Usage and Limits</h3>
+ <div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] space-y-4" id="account-storage">
+ {% for row in usage_limits %}
+ {% set pct = row.percentage %}
+ <div>
+ <div class="flex items-baseline justify-between gap-3 text-sm">
+ <span class="font-medium text-[var(--text-secondary)]"><i class="fas {{ row.icon }} mr-1.5 text-[var(--text-muted)]"></i><span data-i18n="{{ row.label_key }}">{{ row.key }}</span></span>
+ {% if row.limit %}
+ <span class="text-[var(--text-primary)] tabular-nums whitespace-nowrap" data-i18n="account.storageOfQuota" data-i18n-params='{"used": "{{ row.used }}", "quota": "{{ row.limit }}"}'>{{ row.used }} of {{ row.limit }}</span>
+ {% else %}
+ <span class="text-[var(--text-primary)] tabular-nums whitespace-nowrap" data-i18n="account.storageNoLimit" data-i18n-params='{"used": "{{ row.used }}"}'>{{ row.used }} used, no limit</span>
+ {% endif %}
+ </div>
+ {% if row.limit %}
+ <div class="w-full bg-[var(--bg-secondary)] rounded-full h-2 mt-2">
+ <div class="h-2 rounded-full {% if pct >= 100 %}bg-[var(--text-danger-strong)]{% elif pct >= 80 %}bg-[var(--text-warn-strong)]{% else %}bg-[var(--text-success-strong)]{% endif %}" style="width: {{ [pct, 100]|min }}%"></div>
+ </div>
+ {% if row.key == 'storage' and pct >= 100 %}
+ <p class="text-xs text-[var(--text-danger-strong)] mt-2" data-i18n="account.storageFull">Your storage is full. Uploads and new recordings are refused until you delete recordings or remove their audio.</p>
+ {% endif %}
+ {% endif %}
+ </div>
+ {% endfor %}
+ <p class="text-xs text-[var(--text-muted)] border-t border-[var(--border-primary)] pt-3" data-i18n="account.usageHelp">AI tokens and transcription minutes count from the start of each month. Storage counts the audio and video you keep; recordings with their audio removed do not count.</p>
+ </div>
+ </div>
+ {% endif %}
+
<!-- Sign-in & Security — combines the Single Sign-On
provider controls and the password (change /
set) flow into one section since they're both
ways the user authenticates into the account.
"Go to Recordings" link removed; the
page-header Speakr logo is the natural exit. -->
- <div class="mt-6">
+ <div>
<h3 class="text-lg font-medium text-[var(--text-secondary)] mb-2" data-i18n="account.signInSecurity">Sign-in & Security</h3>
<div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] space-y-4">
{% if sso_enabled %}