Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
add filename
Murtaza Nasira949ddf814ef
diff --git a/app.py b/app.pyindex 408d7f3d..45261951 100644--- a/app.py+++ b/app.py@@ -100,6 +100,7 @@ class Recording(db.Model):created_at = db.Column(db.DateTime, default=datetime.utcnow)meeting_date = db.Column(db.Date, nullable=True) # <-- ADDED: Meeting Date fieldfile_size = db.Column(db.Integer) # Store file size in bytes+ original_filename = db.Column(db.String(500), nullable=True) # Store the original uploaded filenamedef to_dict(self):return {@@ -115,6 +116,7 @@ class Recording(db.Model):'created_at': self.created_at.isoformat() if self.created_at else None,'meeting_date': self.meeting_date.isoformat() if self.meeting_date else None, # <-- ADDED: Include meeting_date'file_size': self.file_size,+ 'original_filename': self.original_filename, # <-- ADDED: Include original filename'user_id': self.user_id}@@ -789,9 +791,10 @@ def upload_file():if file.filename == '':return jsonify({'error': 'No file selected'}), 400- filename = secure_filename(file.filename)+ original_filename = file.filename # <-- ADDED: Capture original filename+ safe_filename = secure_filename(original_filename)# Ensure filepath uses the configured UPLOAD_FOLDER- filepath = os.path.join(app.config['UPLOAD_FOLDER'], f"{datetime.now().strftime('%Y%m%d%H%M%S')}_{filename}")+ filepath = os.path.join(app.config['UPLOAD_FOLDER'], f"{datetime.now().strftime('%Y%m%d%H%M%S')}_{safe_filename}")# Get file size before savingfile.seek(0, os.SEEK_END)@@ -808,8 +811,9 @@ def upload_file():# Create initial database entry with PENDING status and filename as placeholder titlerecording = Recording(audio_path=filepath,- # Use filename (without path part) as initial title- title=f"Recording - {filename}",+ original_filename=original_filename, # <-- ADDED: Save original filename+ # Use original filename (without path part) as initial title+ title=f"Recording - {original_filename}",file_size=file_size,status='PENDING', # Explicitly set statusmeeting_date=datetime.utcnow().date(), # <-- ADDED: Default meeting_date to today@@ -823,7 +827,7 @@ def upload_file():thread = threading.Thread(target=transcribe_audio_task,# Pass original filename for logging clarity- args=(app.app_context(), recording.id, filepath, filename)+ args=(app.app_context(), recording.id, filepath, original_filename) # Pass original_filename here too)thread.start()app.logger.info(f"Background processing thread started for recording ID: {recording.id}")diff --git a/migrate_original_filename.py b/migrate_original_filename.pynew file mode 100644index 00000000..acb29499--- /dev/null+++ b/migrate_original_filename.py@@ -0,0 +1,101 @@+#!/usr/bin/env python3++import os+import sys+from sqlalchemy import inspect+from sqlalchemy.exc import OperationalError++# Try to import from app context+try:+ from flask import current_app+ app = current_app._get_current_object()+ with app.app_context():+ db = app.extensions['sqlalchemy'].db+except (RuntimeError, AttributeError, KeyError):+ # If not in app context, import directly+ try:+ from app import app, db, Recording+ except ImportError as e:+ print(f"Error: Could not import 'app' and 'db': {e}")+ print("Make sure migrate_original_filename.py is runnable and PYTHONPATH is set.")+ sys.exit(1)++def migrate_database():+ """+ Migrate the database schema to add original_filename column without losing data+ """+ print("Starting database migration for original_filename column...")++ with app.app_context():+ inspector = inspect(db.engine)++ # Check if Recording.original_filename column exists+ recording_columns = [column['name'] for column in inspector.get_columns('recording')]+ if 'original_filename' not in recording_columns:+ print("Adding original_filename column to Recording table...")+ try:+ # Add original_filename column to Recording table+ with db.engine.begin() as conn:+ conn.execute(db.text("ALTER TABLE recording ADD COLUMN original_filename VARCHAR(500)"))+ print("original_filename column added successfully!")+ except OperationalError as e:+ print(f"Error adding original_filename column: {e}")+ print("Attempting alternative approach...")+ try:+ # SQLite doesn't support ALTER TABLE ADD COLUMN with foreign keys+ # So we need to create a new table, copy data, drop old table, rename new table++ # 1. Create temporary table with new schema+ with db.engine.begin() as conn:+ conn.execute(db.text("""+ CREATE TABLE recording_new (+ id INTEGER PRIMARY KEY,+ title VARCHAR(200),+ participants VARCHAR(500),+ notes TEXT,+ transcription TEXT,+ summary TEXT,+ status VARCHAR(50),+ audio_path VARCHAR(500),+ created_at DATETIME,+ meeting_date DATE,+ file_size INTEGER,+ user_id INTEGER REFERENCES user(id),+ original_filename VARCHAR(500)+ )+ """))++ # 2. Copy data from old table to new table+ with db.engine.begin() as conn:+ conn.execute(db.text("""+ INSERT INTO recording_new (+ id, title, participants, notes, transcription, summary,+ status, audio_path, created_at, meeting_date, file_size, user_id+ )+ SELECT+ id, title, participants, notes, transcription, summary,+ status, audio_path, created_at, meeting_date, file_size, user_id+ FROM recording+ """))++ # 3. Drop old table+ with db.engine.begin() as conn:+ conn.execute(db.text("DROP TABLE recording"))++ # 4. Rename new table+ with db.engine.begin() as conn:+ conn.execute(db.text("ALTER TABLE recording_new RENAME TO recording"))++ print("original_filename column added successfully using table recreation!")+ except Exception as e2:+ print(f"Error during table recreation: {e2}")+ sys.exit(1)+ else:+ print("original_filename column already exists in Recording table.")++ print("Database migration completed successfully!")++if __name__ == "__main__":+ print("Attempting to migrate the database to add original_filename column...")+ migrate_database()+ print("Database migration process finished.")diff --git a/templates/index.html b/templates/index.htmlindex 49dadf75..0fc176f1 100644--- a/templates/index.html+++ b/templates/index.html@@ -139,16 +139,37 @@div[v-if="!editingParticipants"],div[v-if="!editingNotes"] {border-radius: 0.75rem !important; /* rounded-xl */+ }+ .metadata-panel {+ background-color: var(--bg-tertiary);+ border: 1px solid var(--border-primary);+ border-radius: 0.5rem; /* rounded-lg */+ padding: 0.75rem 1rem; /* p-3 px-4 */+ margin-top: 0.75rem; /* mt-3 */+ font-size: 0.875rem; /* text-sm */+ color: var(--text-secondary);+ }+ .metadata-panel dt {+ font-weight: 500;+ color: var(--text-primary);+ margin-bottom: 0.1rem;+ }+ .metadata-panel dd {+ margin-left: 0;+ margin-bottom: 0.5rem;+ word-break: break-all; /* Wrap long filenames */}.status-badge {display: inline-block;- padding: 0.25rem 0.75rem; /* px-3 py-1 */- font-size: 0.75rem; /* text-xs */+ padding: 0.15rem 0.6rem; /* Smaller padding */+ font-size: 0.65rem; /* Smaller text */font-weight: 500; /* font-medium */border-radius: 9999px; /* rounded-full */- margin-top: 0.5rem; /* mt-2 */+ /* margin-top: 0.5rem; /* mt-2 */ /* Removed margin-top */box-shadow: 0 1px 2px rgba(0,0,0,0.05);letter-spacing: 0.025em;+ vertical-align: middle; /* Align with text */+ margin-left: 0.75rem; /* Add some space */}.status-processing { color: #1d4ed8; background-color: #dbeafe; } /* text-blue-800 bg-blue-100 */.status-summarizing { color: #92400e; background-color: #fef3c7; } /* text-amber-800 bg-amber-100 */@@ -532,11 +553,14 @@</button></span></span>- Created: ${ new Date(selectedRecording.created_at).toLocaleString() } | Size: ${ formatFileSize(selectedRecording.file_size) }+ Created: ${ new Date(selectedRecording.created_at).toLocaleString() }+ <!-- Status Badge Moved Here -->+ <span :class="getStatusClass(selectedRecording.status)" class="status-badge">+ ${ formatStatus(selectedRecording.status) }+ </span></p>- <span :class="getStatusClass(selectedRecording.status)" class="status-badge">- Status: ${ formatStatus(selectedRecording.status) }- </span>+ <!-- Removed Size from here -->+ <!-- Removed separate Status Badge span --></div><div class="flex space-x-2 flex-shrink-0"><button @click="editRecording(selectedRecording)" class="px-3 py-1.5 bg-[var(--bg-button)] text-[var(--text-button)] rounded-md hover:bg-[var(--bg-button-hover)] text-sm shadow-sm">@@ -628,6 +652,20 @@<div v-if="!editingNotes" class="text-sm bg-[var(--bg-tertiary)] p-3 rounded-xl border border-[var(--border-primary)] custom-scrollbar text-[var(--text-secondary)]" style="height: 200px;" v-html="selectedRecording.notes_html || selectedRecording.notes || 'No notes'"></div><textarea v-else v-model="selectedRecording.notes" @blur="saveInlineEdit('notes')" class="text-sm bg-[var(--bg-tertiary)] p-3 rounded border border-[var(--border-primary)] custom-scrollbar text-[var(--text-secondary)] w-full focus:ring-[var(--ring-focus)] focus:border-[var(--border-focus)]" style="height: 200px;" placeholder="Enter notes"></textarea></div>++ <!-- Metadata Panel -->+ <div class="metadata-panel">+ <dl>+ <div v-if="selectedRecording.original_filename">+ <dt>Original Filename</dt>+ <dd>${ selectedRecording.original_filename }</dd>+ </div>+ <div>+ <dt>File Size</dt>+ <dd>${ formatFileSize(selectedRecording.file_size) }</dd>+ </div>+ </dl>+ </div></div></div></div>