Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
add llm for title + summary
Murtaza Nasir0b46c1fba367
diff --git a/.gitignore b/.gitignoreindex 2b51a294..79420b2e 100644--- a/.gitignore+++ b/.gitignore@@ -1,4 +1,10 @@venv/__pycache__/instance/-uploads/\ No newline at end of file+uploads/+*.db+*.db-journal+__pycache__/+*.pyc+*.log+.env\ No newline at end of filediff --git a/app.py b/app.pyindex 4dd0725d..9d1c064f 100644--- a/app.py+++ b/app.py@@ -1,35 +1,46 @@# app.py+import os+import sysfrom flask import Flask, render_template, request, jsonify, send_filefrom flask_sqlalchemy import SQLAlchemyfrom datetime import datetime-import os-from openai import OpenAI+from openai import OpenAI # Keep using the OpenAI libraryimport jsonfrom werkzeug.utils import secure_filenamefrom werkzeug.exceptions import RequestEntityTooLargefrom sqlalchemy import select-import threading # Import threading+import threading+from dotenv import load_dotenv # Import load_dotenv+import httpx+import re++# Load environment variables from .env file+load_dotenv()app = Flask(__name__)-app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////opt/transcription-app/instance/transcriptions.db' # Make sure path is correct-app.config['UPLOAD_FOLDER'] = 'uploads'+# Ensure the path uses the directory structure from your setup script+app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////opt/transcription-app/instance/transcriptions.db'+app.config['UPLOAD_FOLDER'] = '/opt/transcription-app/uploads' # Use absolute path based on setupapp.config['MAX_CONTENT_LENGTH'] = 250 * 1024 * 1024 # 250MB max file sizedb = SQLAlchemy()db.init_app(app)# Ensure upload and instance directories existos.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)-# os.makedirs(os.path.dirname(app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '')), exist_ok=True)+# Assuming the instance folder is handled correctly by Flask or created by setup.sh+# os.makedirs(os.path.dirname(app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '/')), exist_ok=True)# --- Database Models ---class Recording(db.Model):id = db.Column(db.Integer, primary_key=True)- title = db.Column(db.String(200))+ # Title will now often be AI-generated, maybe start with filename?+ title = db.Column(db.String(200), nullable=True) # Allow Null initiallyparticipants = db.Column(db.String(500))notes = db.Column(db.Text)- transcription = db.Column(db.Text, nullable=True) # Allow null initially- status = db.Column(db.String(50), default='PENDING') # Add status field: PENDING, PROCESSING, COMPLETED, FAILED+ transcription = db.Column(db.Text, nullable=True)+ summary = db.Column(db.Text, nullable=True) # <-- ADDED: Summary field+ status = db.Column(db.String(50), default='PENDING') # PENDING, PROCESSING, SUMMARIZING, COMPLETED, FAILEDaudio_path = db.Column(db.String(500))created_at = db.Column(db.DateTime, default=datetime.utcnow)file_size = db.Column(db.Integer) # Store file size in bytes@@ -41,7 +52,8 @@ class Recording(db.Model):'participants': self.participants,'notes': self.notes,'transcription': self.transcription,- 'status': self.status, # Include status+ 'summary': self.summary, # <-- ADDED: Include summary+ 'status': self.status,'created_at': self.created_at.isoformat() if self.created_at else None,'file_size': self.file_size}@@ -49,45 +61,182 @@ class Recording(db.Model):with app.app_context():db.create_all()-# --- API client setup ----# Ensure you have your API key and base URL configured correctly-# For local testing, you might use environment variables or a config file-client = OpenAI(- api_key=os.environ.get("OPENAI_API_KEY", "cant-be-empty"), # Use env var or default- base_url=os.environ.get("OPENAI_BASE_URL", "http://192.168.68.85:1611/v1/") # Use env var or default-)--# --- Background Transcription Task ----def transcribe_audio_task(app_context, recording_id, filepath):- """Runs the transcription in a background thread."""+# --- API client setup for OpenRouter ---+# Use environment variables from .env+openrouter_api_key = os.environ.get("OPENROUTER_API_KEY")+openrouter_base_url = os.environ.get("OPENROUTER_BASE_URL", "https://openrouter.ai/api/v1")+openrouter_model_name = os.environ.get("OPENROUTER_MODEL_NAME", "openai/gpt-3.5-turbo") # Default if not set++http_client_no_proxy = httpx.Client(verify=True) # verify=True is default, but good to be explicit++if not openrouter_api_key:+ app.logger.warning("OPENROUTER_API_KEY not found. Title/Summary generation DISABLED.")+else:+ try:+ # ---> Pass the custom httpx_client <---+ client = OpenAI(+ api_key=openrouter_api_key,+ base_url=openrouter_base_url,+ http_client=http_client_no_proxy # Pass the proxy-disabled client+ )+ app.logger.info(f"OpenRouter client initialized. Using model: {openrouter_model_name}")+ except Exception as client_init_e:+ app.logger.error(f"Failed to initialize OpenRouter client: {client_init_e}", exc_info=True)++# Store details for the transcription client (potentially different)+transcription_api_key = os.environ.get("OPENAI_API_KEY", "cant-be-empty")+transcription_base_url = os.environ.get("OPENAI_BASE_URL", "http://192.168.68.85:1611/v1/")++app.logger.info(f"Using OpenRouter model for summaries: {openrouter_model_name}")++# --- Background Transcription & Summarization Task ---+def transcribe_audio_task(app_context, recording_id, filepath, original_filename):+ """Runs the transcription and summarization in a background thread."""with app_context: # Need app context for db operations in threadrecording = db.session.get(Recording, recording_id)if not recording:- print(f"Error: Recording {recording_id} not found for transcription.")+ app.logger.error(f"Error: Recording {recording_id} not found for transcription.")returntry:- print(f"Starting transcription for recording {recording_id}...")+ app.logger.info(f"Starting transcription for recording {recording_id} ({original_filename})...")recording.status = 'PROCESSING'db.session.commit()+ # --- Step 1: Transcription ---with open(filepath, 'rb') as audio_file:- transcript = client.audio.transcriptions.create(- model="Systran/faster-distil-whisper-large-v3", # Or your desired model+ # NOTE: This still uses the hardcoded Whisper model.+ # If you want OpenRouter for transcription too, change the model here+ # and potentially adjust the API call if needed.+ # For now, assuming Whisper via a local compatible endpoint.+ # You might need a *separate* client for Whisper if it's at a different URL.+ # Example using the configured client (assuming it points to Whisper or OpenRouter handles it):+ transcription_client = OpenAI(+ api_key=transcription_api_key,+ base_url=transcription_base_url,+ http_client=http_client_no_proxy # Reuse the same client configuration+ )+ transcript = transcription_client.audio.transcriptions.create(+ model="Systran/faster-distil-whisper-large-v3", # Your Whisper modelfile=audio_file,language="en" # Specify language if known)-recording.transcription = transcript.text- recording.status = 'COMPLETED'- print(f"Transcription COMPLETED for recording {recording_id}.")+ app.logger.info(f"Transcription completed for recording {recording_id}. Text length: {len(recording.transcription)}")+ # Don't commit yet, proceed to summarization++ # --- Step 2: Title & Summary Generation using OpenRouter ---+ if client is None: # Check if OpenRouter client initialized successfully earlier+ app.logger.warning(f"Skipping summary for {recording_id}: OpenRouter client not configured.")+ recording.summary = "[Summary skipped: OpenRouter client not configured]"+ recording.status = 'COMPLETED'+ db.session.commit()+ return # Exit cleanly++ recording.status = 'SUMMARIZING' # Update statusdb.session.commit()+ app.logger.info(f"Requesting title and summary from OpenRouter for recording {recording_id} using model {openrouter_model_name}...")++ if not recording.transcription or len(recording.transcription.strip()) < 10: # Basic check for valid transcript+ app.logger.warning(f"Transcription for recording {recording_id} is too short or empty. Skipping summarization.")+ recording.status = 'COMPLETED' # Mark as completed even without summary+ recording.summary = "[Summary skipped due to short transcription]"+ db.session.commit()+ return # Exit the task cleanly++ # Prepare the prompt for OpenRouter+ prompt_text = f"""Analyze the following audio transcription and generate a concise title and a brief summary.++Transcription:+\"\"\"+{recording.transcription[:30000]}+\"\"\"++Respond STRICTLY with a JSON object containing two keys: "title" (a short, descriptive title, max 15 words) and "summary" (a paragraph summarizing the key points, max 150 words).+Example Format:+{{+ "title": "Example Meeting Discussion on Q3 Results",+ "summary": "The meeting covered the financial results for Q3, highlighting key achievements and areas for improvement. Action items were assigned for follow-up."+}}++JSON Response:""" # The prompt guides the model towards the desired output++ try:+ # Use the OpenRouter client configured earlier+ completion = client.chat.completions.create(+ model=openrouter_model_name,+ messages=[+ {"role": "system", "content": "You are an AI assistant that generates titles and summaries for meeting transcripts. Respond only with the requested JSON object."},+ {"role": "user", "content": prompt_text}+ ],+ temperature=0.5, # Adjust temperature as needed+ max_tokens=300, # Adjust based on expected title+summary length+ response_format={"type": "json_object"} # Request JSON output+ )++ response_content = completion.choices[0].message.content+ app.logger.debug(f"Raw OpenRouter response for {recording_id}: {response_content}")++ try:+ response_content = completion.choices[0].message.content+ app.logger.debug(f"Raw OpenRouter response for {recording_id}: {response_content}")++ # Use regex to extract JSON content from potential markdown code blocks+ # This looks for content between markdown code blocks or just takes the whole content+ json_match = re.search(r'```(?:json)?(.*?)```|(.+)', response_content, re.DOTALL)++ if json_match:+ # Use the first group that matched (either between ``` or the whole content)+ sanitized_response = json_match.group(1) if json_match.group(1) else json_match.group(2)+ sanitized_response = sanitized_response.strip()+ else:+ sanitized_response = response_content.strip()++ summary_data = json.loads(response_content)+ generated_title = summary_data.get("title")+ generated_summary = summary_data.get("summary")++ if generated_title and generated_summary:+ # Update recording with AI generated content+ recording.title = generated_title.strip()+ recording.summary = generated_summary.strip()+ recording.status = 'COMPLETED'+ app.logger.info(f"Title and summary generated successfully for recording {recording_id}.")+ else:+ app.logger.warning(f"OpenRouter response for {recording_id} lacked 'title' or 'summary' key. Response: {response_content}")+ recording.summary = "[AI summary generation failed: Invalid JSON structure]"+ recording.status = 'COMPLETED' # Still completed, but summary failed++ except json.JSONDecodeError as json_e:+ app.logger.error(f"Failed to parse JSON response from OpenRouter for {recording_id}: {json_e}. Response: {response_content}")+ recording.summary = f"[AI summary generation failed: Invalid JSON response ({json_e})]"+ recording.status = 'COMPLETED' # Mark as completed, summary failed++ except Exception as summary_e:+ app.logger.error(f"Error calling OpenRouter API for summary ({recording_id}): {str(summary_e)}")+ # Keep transcription, but mark summary failed. Don't change status from SUMMARIZING yet.+ recording.summary = f"[AI summary generation failed: API Error ({str(summary_e)})]"+ recording.status = 'COMPLETED' # Even if summary fails, transcription worked.+++ db.session.commit() # Final commit for this stepexcept Exception as e:- print(f"Transcription FAILED for recording {recording_id}: {str(e)}")- recording.transcription = f"Transcription failed: {str(e)}" # Store error message- recording.status = 'FAILED'- db.session.commit()+ db.session.rollback() # Rollback if any step failed critically+ app.logger.error(f"Processing FAILED for recording {recording_id}: {str(e)}", exc_info=True)+ # Retrieve recording again in case session was rolled back+ recording = db.session.get(Recording, recording_id)+ if recording:+ # Ensure status reflects failure even after rollback/retrieve attempt+ if recording.status not in ['COMPLETED', 'FAILED']: # Avoid overwriting final state+ recording.status = 'FAILED'+ if not recording.transcription: # If transcription itself failed+ recording.transcription = f"Processing failed: {str(e)}"+ # Add error note to summary if appropriate stage was reached+ if recording.status == 'SUMMARIZING' and not recording.summary:+ recording.summary = f"[Processing failed during summarization: {str(e)}]"++ db.session.commit()# --- Flask Routes ---@@ -107,29 +256,22 @@ def get_recordings():@app.route('/save', methods=['POST'])def save_metadata():- # This route remains largely the same, just updates metadatatry:data = request.json- if not data:- return jsonify({'error': 'No data provided'}), 400-+ if not data: return jsonify({'error': 'No data provided'}), 400recording_id = data.get('id')- if not recording_id:- return jsonify({'error': 'No recording ID provided'}), 400+ if not recording_id: return jsonify({'error': 'No recording ID provided'}), 400recording = db.session.get(Recording, recording_id)- if not recording:- return jsonify({'error': 'Recording not found'}), 404+ if not recording: return jsonify({'error': 'Recording not found'}), 404# Update fields if provided- if 'title' in data:- recording.title = data['title']- if 'participants' in data:- recording.participants = data['participants']- if 'notes' in data:- recording.notes = data['notes']- # Do not update transcription or status here+ if 'title' in data: recording.title = data['title']+ if 'participants' in data: recording.participants = data['participants']+ if 'notes' in data: recording.notes = data['notes']+ if 'summary' in data: recording.summary = data['summary'] # <-- ADDED: Allow saving edited summary+ # Do not update transcription or status heredb.session.commit()return jsonify({'success': True, 'recording': recording.to_dict()})@@ -138,6 +280,7 @@ def save_metadata():app.logger.error(f"Error saving metadata for recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500+@app.route('/upload', methods=['POST'])def upload_file():try:@@ -149,42 +292,44 @@ def upload_file():return jsonify({'error': 'No file selected'}), 400filename = secure_filename(file.filename)- filepath = os.path.join(app.config['UPLOAD_FOLDER'], 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}")# Get file size before savingfile.seek(0, os.SEEK_END)file_size = file.tell()file.seek(0)- # Check size limit again (Flask's MAX_CONTENT_LENGTH handles the actual request blocking)+ # Check size limit againif file_size > app.config['MAX_CONTENT_LENGTH']:- raise RequestEntityTooLarge()+ raise RequestEntityTooLarge()file.save(filepath)- print(f"File saved to {filepath}")+ app.logger.info(f"File saved to {filepath}")- # Create initial database entry with PENDING status+ # Create initial database entry with PENDING status and filename as placeholder titlerecording = Recording(audio_path=filepath,- title=f"Untitled - {datetime.now().strftime('%Y-%m-%d %H:%M')}", # Simpler default title+ # Use filename (without path part) as initial title+ title=f"Recording - {filename}",file_size=file_size,status='PENDING' # Explicitly set status)db.session.add(recording)db.session.commit()- print(f"Initial recording record created with ID: {recording.id}")+ app.logger.info(f"Initial recording record created with ID: {recording.id}")- # --- Start transcription in background thread ---- # Pass the app context to the thread+ # --- Start transcription & summarization in background thread ---thread = threading.Thread(target=transcribe_audio_task,- args=(app.app_context(), recording.id, filepath)+ # Pass original filename for logging clarity+ args=(app.app_context(), recording.id, filepath, filename))thread.start()- print(f"Background transcription thread started for recording ID: {recording.id}")+ app.logger.info(f"Background processing thread started for recording ID: {recording.id}")# Return the initial recording data and ID immediately- return jsonify(recording.to_dict()), 202 # 202 Accepted indicates processing started+ return jsonify(recording.to_dict()), 202 # 202 Acceptedexcept RequestEntityTooLarge:max_size_mb = app.config['MAX_CONTENT_LENGTH'] / (1024 * 1024)@@ -198,37 +343,36 @@ def upload_file():app.logger.error(f"Error during file upload: {e}", exc_info=True)return jsonify({'error': str(e)}), 500-# --- NEW: Status Endpoint ---++# Status Endpoint (no changes needed, it returns the full recording dict)@app.route('/status/<int:recording_id>', methods=['GET'])def get_status(recording_id):- """Endpoint to check the transcription status."""+ """Endpoint to check the transcription/summarization status."""try:recording = db.session.get(Recording, recording_id)if not recording:return jsonify({'error': 'Recording not found'}), 404-- # Return the full recording data, including status and transcription (if available)return jsonify(recording.to_dict())-except Exception as e:app.logger.error(f"Error fetching status for recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500-+# Get Audio Endpoint (no changes needed)@app.route('/audio/<int:recording_id>')def get_audio(recording_id):try:recording = db.session.get(Recording, recording_id)if not recording or not recording.audio_path:return jsonify({'error': 'Recording or audio file not found'}), 404- # Ensure the file actually exists before trying to send itif not os.path.exists(recording.audio_path):- return jsonify({'error': 'Audio file missing from server'}), 404+ app.logger.error(f"Audio file missing from server: {recording.audio_path}")+ return jsonify({'error': 'Audio file missing from server'}), 404return send_file(recording.audio_path)except Exception as e:app.logger.error(f"Error serving audio for recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500+# Delete Recording Endpoint (no changes needed functionally)@app.route('/recording/<int:recording_id>', methods=['DELETE'])def delete_recording(recording_id):try:@@ -240,15 +384,14 @@ def delete_recording(recording_id):try:if recording.audio_path and os.path.exists(recording.audio_path):os.remove(recording.audio_path)- print(f"Deleted audio file: {recording.audio_path}")+ app.logger.info(f"Deleted audio file: {recording.audio_path}")except Exception as e:- # Log error but proceed to delete DB recordapp.logger.error(f"Error deleting audio file {recording.audio_path}: {e}")# Delete the database recorddb.session.delete(recording)db.session.commit()- print(f"Deleted recording record ID: {recording_id}")+ app.logger.info(f"Deleted recording record ID: {recording_id}")return jsonify({'success': True})except Exception as e:@@ -256,7 +399,9 @@ def delete_recording(recording_id):app.logger.error(f"Error deleting recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500+if __name__ == '__main__':- # Use waitress or gunicorn in production instead of Flask's dev server- # Example: waitress-serve --host 0.0.0.0 --port 8899 app:app- app.run(host='0.0.0.0', port=8899, debug=True) # debug=True reloads, which can interfere with threads. Set False for testing threads properly. Consider waitress for better threading.\ No newline at end of file+ # Consider using waitress or gunicorn for production+ # waitress-serve --host 0.0.0.0 --port 8899 app:app+ # For development:+ app.run(host='0.0.0.0', port=8899, debug=True) # Set debug=False if thread issues arise\ No newline at end of filediff --git a/deployment/setup.sh b/deployment/setup.shindex 901c9249..6c11dafb 100755--- a/deployment/setup.sh+++ b/deployment/setup.sh@@ -38,6 +38,7 @@ After=network.target[Service]User=$USER+EnvironmentFile=/opt/transcription-app/.envWorkingDirectory=/opt/transcription-appEnvironment="PATH=/opt/transcription-app/venv/bin"Environment="PYTHONPATH=/opt/transcription-app"diff --git a/notes.md b/notes.mdindex f7074339..66ce56a0 100644--- a/notes.md+++ b/notes.md@@ -2,4 +2,7 @@python create_docs.py-## start/stop\ No newline at end of file+## start/stop++source venv/bin/activate+gunicorn --workers 3 --bind 0.0.0.0:8899 --timeout 600 app:app\ No newline at end of filediff --git a/project_files.md b/project_files.mdindex 13a00931..20e6cc0b 100644--- a/project_files.md+++ b/project_files.md@@ -13,55 +13,98 @@ Generated documentation of all project files.import osimport sys# Add project root to path if necessary for 'app' import-# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) # Adjust path as needed+# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))++# Load environment variables in case DB path relies on them (optional here)+# from dotenv import load_dotenv+# load_dotenv()# Check if running within app context already (e.g., via Flask command)try:from flask import current_app+ # Ensure app context is pushed if needed for config accessapp = current_app._get_current_object()- db = app.extensions['sqlalchemy'].db # Access db via extensions typical pattern-except RuntimeError:- # If not in app context, import directly (assuming reset_db.py is at the same level as app.py)- # This might be needed if running `python reset_db.py` directly+ # Make sure db is initialized within the app context if needed+ # (SQLAlchemy initialization in app.py handles this mostly)+ with app.app_context():+ db = app.extensions['sqlalchemy'].db # Access db via extensions+except (RuntimeError, AttributeError, KeyError):+ # If not in app context, import directlytry:+ # Ensure this import reflects the updated app.py with the new modelfrom app import app, db- except ImportError:- print("Error: Could not import 'app' and 'db'. Ensure reset_db.py is runnable.")- print("Make sure your PYTHONPATH includes the project directory or run using 'flask run <command>'")+ except ImportError as e:+ print(f"Error: Could not import 'app' and 'db': {e}")+ print("Make sure reset_db.py is runnable and PYTHONPATH is set.")sys.exit(1)-def reset_database():# Determine the database path relative to the instance folder- # Assuming app is configured with instance_relative_config=True (default)- # or manually construct path if instance folder is known+ # Use app config if availableinstance_path = app.instance_path if hasattr(app, 'instance_path') else os.path.join(os.getcwd(), 'instance')- db_filename = app.config.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///instance/transcriptions.db').split('/')[-1]- db_path = os.path.join(instance_path, db_filename)+ try:+ # Ensure app context for config access if not already present+ with app.app_context():+ # Use absolute path from config+ db_uri = app.config.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///instance/transcriptions.db')+ # Handle relative vs absolute paths specified in URI+ if db_uri.startswith('sqlite:///'):+ # Assume absolute path from URI root if starts with '///'+ db_path = db_uri.replace('sqlite:///', '/', 1) # Replace only first+ # Ensure instance path reflects the directory containing the DB+ instance_path = os.path.dirname(db_path)+ elif db_uri.startswith('sqlite://'):+ # Assume relative path from instance folder+ db_filename = db_uri.split('/')[-1]+ db_path = os.path.join(instance_path, db_filename)+ else: # Handle other DB types or formats if needed+ print(f"Warning: Non-SQLite URI detected: {db_uri}. Deletion logic might need adjustment.")+ # Attempt to parse or fallback+ db_filename = db_uri.split('/')[-1] # Best guess+ db_path = os.path.join(instance_path, db_filename)++ except Exception as config_e:+ print(f"Error accessing app config for DB path: {config_e}. Using default.")+ # Fallback if config access fails+ instance_path = os.path.join(os.getcwd(), 'instance')+ db_filename = 'transcriptions.db'+ db_path = os.path.join(instance_path, db_filename)# Ensure instance directory exists+ print(f"Ensuring instance directory exists: {instance_path}")os.makedirs(instance_path, exist_ok=True)+ print(f"Database path identified as: {db_path}")# Remove existing database if it existsif os.path.exists(db_path):print(f"Removing existing database at {db_path}")try:os.remove(db_path)+ # Also remove journal file if it exists+ journal_path = db_path + "-journal"+ if os.path.exists(journal_path):+ os.remove(journal_path)+ print(f"Removing existing journal file at {journal_path}")except OSError as e:print(f"Error removing database file: {e}. Check permissions or if it's in use.")- # Optionally exit or continue to create tables anyway+ # Decide whether to exit or continue# sys.exit(1)# Create application context to work with the database- with app.app_context():- print("Creating new database schema...")- # Create all tables defined in models- try:+ try:+ with app.app_context():+ print("Creating new database schema (including 'summary' column)...")+ # Create all tables defined in models (app.py)db.create_all()print("Database schema created successfully!")- except Exception as e:- print(f"Error creating database schema: {e}")- sys.exit(1)+ except Exception as e:+ print(f"Error creating database schema: {e}")+ # Attempt rollback if possible (though less relevant for create_all)+ try:+ db.session.rollback()+ except Exception as rb_e:+ print(f"Rollback attempt failed: {rb_e}")+ sys.exit(1)if __name__ == "__main__":print("Attempting to reset the database...")@@ -75,37 +118,47 @@ if __name__ == "__main__":```python# app.py+import os+import sysfrom flask import Flask, render_template, request, jsonify, send_filefrom flask_sqlalchemy import SQLAlchemyfrom datetime import datetime-import os-from openai import OpenAI+from openai import OpenAI # Keep using the OpenAI libraryimport jsonfrom werkzeug.utils import secure_filenamefrom werkzeug.exceptions import RequestEntityTooLargefrom sqlalchemy import select-import threading # Import threading+import threading+from dotenv import load_dotenv # Import load_dotenv+import httpx++# Load environment variables from .env file+load_dotenv()app = Flask(__name__)-app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///instance/transcriptions.db' # Make sure path is correct-app.config['UPLOAD_FOLDER'] = 'uploads'+# Ensure the path uses the directory structure from your setup script+app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////opt/transcription-app/instance/transcriptions.db'+app.config['UPLOAD_FOLDER'] = '/opt/transcription-app/uploads' # Use absolute path based on setupapp.config['MAX_CONTENT_LENGTH'] = 250 * 1024 * 1024 # 250MB max file sizedb = SQLAlchemy()db.init_app(app)# Ensure upload and instance directories existos.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)-os.makedirs(os.path.dirname(app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '')), exist_ok=True)+# Assuming the instance folder is handled correctly by Flask or created by setup.sh+# os.makedirs(os.path.dirname(app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '/')), exist_ok=True)# --- Database Models ---class Recording(db.Model):id = db.Column(db.Integer, primary_key=True)- title = db.Column(db.String(200))+ # Title will now often be AI-generated, maybe start with filename?+ title = db.Column(db.String(200), nullable=True) # Allow Null initiallyparticipants = db.Column(db.String(500))notes = db.Column(db.Text)- transcription = db.Column(db.Text, nullable=True) # Allow null initially- status = db.Column(db.String(50), default='PENDING') # Add status field: PENDING, PROCESSING, COMPLETED, FAILED+ transcription = db.Column(db.Text, nullable=True)+ summary = db.Column(db.Text, nullable=True) # <-- ADDED: Summary field+ status = db.Column(db.String(50), default='PENDING') # PENDING, PROCESSING, SUMMARIZING, COMPLETED, FAILEDaudio_path = db.Column(db.String(500))created_at = db.Column(db.DateTime, default=datetime.utcnow)file_size = db.Column(db.Integer) # Store file size in bytes@@ -117,7 +170,8 @@ class Recording(db.Model):'participants': self.participants,'notes': self.notes,'transcription': self.transcription,- 'status': self.status, # Include status+ 'summary': self.summary, # <-- ADDED: Include summary+ 'status': self.status,'created_at': self.created_at.isoformat() if self.created_at else None,'file_size': self.file_size}@@ -125,45 +179,169 @@ class Recording(db.Model):with app.app_context():db.create_all()-# --- API client setup ----# Ensure you have your API key and base URL configured correctly-# For local testing, you might use environment variables or a config file-client = OpenAI(- api_key=os.environ.get("OPENAI_API_KEY", "cant-be-empty"), # Use env var or default- base_url=os.environ.get("OPENAI_BASE_URL", "http://192.168.68.85:1611/v1/") # Use env var or default-)--# --- Background Transcription Task ----def transcribe_audio_task(app_context, recording_id, filepath):- """Runs the transcription in a background thread."""+# --- API client setup for OpenRouter ---+# Use environment variables from .env+openrouter_api_key = os.environ.get("OPENROUTER_API_KEY")+openrouter_base_url = os.environ.get("OPENROUTER_BASE_URL", "https://openrouter.ai/api/v1")+openrouter_model_name = os.environ.get("OPENROUTER_MODEL_NAME", "openai/gpt-3.5-turbo") # Default if not set++http_client_no_proxy = httpx.Client(verify=True) # verify=True is default, but good to be explicit++if not openrouter_api_key:+ app.logger.warning("OPENROUTER_API_KEY not found. Title/Summary generation DISABLED.")+else:+ try:+ # ---> Pass the custom httpx_client <---+ client = OpenAI(+ api_key=openrouter_api_key,+ base_url=openrouter_base_url,+ http_client=http_client_no_proxy # Pass the proxy-disabled client+ )+ app.logger.info(f"OpenRouter client initialized. Using model: {openrouter_model_name}")+ except Exception as client_init_e:+ app.logger.error(f"Failed to initialize OpenRouter client: {client_init_e}", exc_info=True)++# Store details for the transcription client (potentially different)+transcription_api_key = os.environ.get("OPENAI_API_KEY", "cant-be-empty")+transcription_base_url = os.environ.get("OPENAI_BASE_URL", "http://192.168.68.85:1611/v1/")++app.logger.info(f"Using OpenRouter model for summaries: {openrouter_model_name}")++# --- Background Transcription & Summarization Task ---+def transcribe_audio_task(app_context, recording_id, filepath, original_filename):+ """Runs the transcription and summarization in a background thread."""with app_context: # Need app context for db operations in threadrecording = db.session.get(Recording, recording_id)if not recording:- print(f"Error: Recording {recording_id} not found for transcription.")+ app.logger.error(f"Error: Recording {recording_id} not found for transcription.")returntry:- print(f"Starting transcription for recording {recording_id}...")+ app.logger.info(f"Starting transcription for recording {recording_id} ({original_filename})...")recording.status = 'PROCESSING'db.session.commit()+ # --- Step 1: Transcription ---with open(filepath, 'rb') as audio_file:- transcript = client.audio.transcriptions.create(- model="Systran/faster-distil-whisper-large-v3", # Or your desired model+ # NOTE: This still uses the hardcoded Whisper model.+ # If you want OpenRouter for transcription too, change the model here+ # and potentially adjust the API call if needed.+ # For now, assuming Whisper via a local compatible endpoint.+ # You might need a *separate* client for Whisper if it's at a different URL.+ # Example using the configured client (assuming it points to Whisper or OpenRouter handles it):+ transcription_client = OpenAI(+ api_key=transcription_api_key,+ base_url=transcription_base_url,+ http_client=http_client_no_proxy # Reuse the same client configuration+ )+ transcript = transcription_client.audio.transcriptions.create(+ model="Systran/faster-distil-whisper-large-v3", # Your Whisper modelfile=audio_file,language="en" # Specify language if known)-recording.transcription = transcript.text- recording.status = 'COMPLETED'- print(f"Transcription COMPLETED for recording {recording_id}.")+ app.logger.info(f"Transcription completed for recording {recording_id}. Text length: {len(recording.transcription)}")+ # Don't commit yet, proceed to summarization++ # --- Step 2: Title & Summary Generation using OpenRouter ---+ if client is None: # Check if OpenRouter client initialized successfully earlier+ app.logger.warning(f"Skipping summary for {recording_id}: OpenRouter client not configured.")+ recording.summary = "[Summary skipped: OpenRouter client not configured]"+ recording.status = 'COMPLETED'+ db.session.commit()+ return # Exit cleanly++ recording.status = 'SUMMARIZING' # Update statusdb.session.commit()+ app.logger.info(f"Requesting title and summary from OpenRouter for recording {recording_id} using model {openrouter_model_name}...")++ if not recording.transcription or len(recording.transcription.strip()) < 10: # Basic check for valid transcript+ app.logger.warning(f"Transcription for recording {recording_id} is too short or empty. Skipping summarization.")+ recording.status = 'COMPLETED' # Mark as completed even without summary+ recording.summary = "[Summary skipped due to short transcription]"+ db.session.commit()+ return # Exit the task cleanly++ # Prepare the prompt for OpenRouter+ prompt_text = f"""Analyze the following audio transcription and generate a concise title and a brief summary.++Transcription:+\"\"\"+{recording.transcription[:30000]}+\"\"\"++Respond STRICTLY with a JSON object containing two keys: "title" (a short, descriptive title, max 15 words) and "summary" (a paragraph summarizing the key points, max 150 words).+Example Format:+{{+ "title": "Example Meeting Discussion on Q3 Results",+ "summary": "The meeting covered the financial results for Q3, highlighting key achievements and areas for improvement. Action items were assigned for follow-up."+}}++JSON Response:""" # The prompt guides the model towards the desired output++ try:+ # Use the OpenRouter client configured earlier+ completion = client.chat.completions.create(+ model=openrouter_model_name,+ messages=[+ {"role": "system", "content": "You are an AI assistant that generates titles and summaries for meeting transcripts. Respond only with the requested JSON object."},+ {"role": "user", "content": prompt_text}+ ],+ temperature=0.5, # Adjust temperature as needed+ max_tokens=300, # Adjust based on expected title+summary length+ response_format={"type": "json_object"} # Request JSON output+ )++ response_content = completion.choices[0].message.content+ app.logger.debug(f"Raw OpenRouter response for {recording_id}: {response_content}")++ # Parse the JSON response+ try:+ summary_data = json.loads(response_content)+ generated_title = summary_data.get("title")+ generated_summary = summary_data.get("summary")++ if generated_title and generated_summary:+ # Update recording with AI generated content+ recording.title = generated_title.strip()+ recording.summary = generated_summary.strip()+ recording.status = 'COMPLETED'+ app.logger.info(f"Title and summary generated successfully for recording {recording_id}.")+ else:+ app.logger.warning(f"OpenRouter response for {recording_id} lacked 'title' or 'summary' key. Response: {response_content}")+ recording.summary = "[AI summary generation failed: Invalid JSON structure]"+ recording.status = 'COMPLETED' # Still completed, but summary failed++ except json.JSONDecodeError as json_e:+ app.logger.error(f"Failed to parse JSON response from OpenRouter for {recording_id}: {json_e}. Response: {response_content}")+ recording.summary = f"[AI summary generation failed: Invalid JSON response ({json_e})]"+ recording.status = 'COMPLETED' # Mark as completed, summary failed++ except Exception as summary_e:+ app.logger.error(f"Error calling OpenRouter API for summary ({recording_id}): {str(summary_e)}")+ # Keep transcription, but mark summary failed. Don't change status from SUMMARIZING yet.+ recording.summary = f"[AI summary generation failed: API Error ({str(summary_e)})]"+ recording.status = 'COMPLETED' # Even if summary fails, transcription worked.+++ db.session.commit() # Final commit for this stepexcept Exception as e:- print(f"Transcription FAILED for recording {recording_id}: {str(e)}")- recording.transcription = f"Transcription failed: {str(e)}" # Store error message- recording.status = 'FAILED'- db.session.commit()+ db.session.rollback() # Rollback if any step failed critically+ app.logger.error(f"Processing FAILED for recording {recording_id}: {str(e)}", exc_info=True)+ # Retrieve recording again in case session was rolled back+ recording = db.session.get(Recording, recording_id)+ if recording:+ # Ensure status reflects failure even after rollback/retrieve attempt+ if recording.status not in ['COMPLETED', 'FAILED']: # Avoid overwriting final state+ recording.status = 'FAILED'+ if not recording.transcription: # If transcription itself failed+ recording.transcription = f"Processing failed: {str(e)}"+ # Add error note to summary if appropriate stage was reached+ if recording.status == 'SUMMARIZING' and not recording.summary:+ recording.summary = f"[Processing failed during summarization: {str(e)}]"++ db.session.commit()# --- Flask Routes ---@@ -183,29 +361,22 @@ def get_recordings():@app.route('/save', methods=['POST'])def save_metadata():- # This route remains largely the same, just updates metadatatry:data = request.json- if not data:- return jsonify({'error': 'No data provided'}), 400-+ if not data: return jsonify({'error': 'No data provided'}), 400recording_id = data.get('id')- if not recording_id:- return jsonify({'error': 'No recording ID provided'}), 400+ if not recording_id: return jsonify({'error': 'No recording ID provided'}), 400recording = db.session.get(Recording, recording_id)- if not recording:- return jsonify({'error': 'Recording not found'}), 404+ if not recording: return jsonify({'error': 'Recording not found'}), 404# Update fields if provided- if 'title' in data:- recording.title = data['title']- if 'participants' in data:- recording.participants = data['participants']- if 'notes' in data:- recording.notes = data['notes']- # Do not update transcription or status here+ if 'title' in data: recording.title = data['title']+ if 'participants' in data: recording.participants = data['participants']+ if 'notes' in data: recording.notes = data['notes']+ if 'summary' in data: recording.summary = data['summary'] # <-- ADDED: Allow saving edited summary+ # Do not update transcription or status heredb.session.commit()return jsonify({'success': True, 'recording': recording.to_dict()})@@ -214,6 +385,7 @@ def save_metadata():app.logger.error(f"Error saving metadata for recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500+@app.route('/upload', methods=['POST'])def upload_file():try:@@ -225,42 +397,44 @@ def upload_file():return jsonify({'error': 'No file selected'}), 400filename = secure_filename(file.filename)- filepath = os.path.join(app.config['UPLOAD_FOLDER'], 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}")# Get file size before savingfile.seek(0, os.SEEK_END)file_size = file.tell()file.seek(0)- # Check size limit again (Flask's MAX_CONTENT_LENGTH handles the actual request blocking)+ # Check size limit againif file_size > app.config['MAX_CONTENT_LENGTH']:- raise RequestEntityTooLarge()+ raise RequestEntityTooLarge()file.save(filepath)- print(f"File saved to {filepath}")+ app.logger.info(f"File saved to {filepath}")- # Create initial database entry with PENDING status+ # Create initial database entry with PENDING status and filename as placeholder titlerecording = Recording(audio_path=filepath,- title=f"Untitled - {datetime.now().strftime('%Y-%m-%d %H:%M')}", # Simpler default title+ # Use filename (without path part) as initial title+ title=f"Recording - {filename}",file_size=file_size,status='PENDING' # Explicitly set status)db.session.add(recording)db.session.commit()- print(f"Initial recording record created with ID: {recording.id}")+ app.logger.info(f"Initial recording record created with ID: {recording.id}")- # --- Start transcription in background thread ---- # Pass the app context to the thread+ # --- Start transcription & summarization in background thread ---thread = threading.Thread(target=transcribe_audio_task,- args=(app.app_context(), recording.id, filepath)+ # Pass original filename for logging clarity+ args=(app.app_context(), recording.id, filepath, filename))thread.start()- print(f"Background transcription thread started for recording ID: {recording.id}")+ app.logger.info(f"Background processing thread started for recording ID: {recording.id}")# Return the initial recording data and ID immediately- return jsonify(recording.to_dict()), 202 # 202 Accepted indicates processing started+ return jsonify(recording.to_dict()), 202 # 202 Acceptedexcept RequestEntityTooLarge:max_size_mb = app.config['MAX_CONTENT_LENGTH'] / (1024 * 1024)@@ -274,37 +448,36 @@ def upload_file():app.logger.error(f"Error during file upload: {e}", exc_info=True)return jsonify({'error': str(e)}), 500-# --- NEW: Status Endpoint ---++# Status Endpoint (no changes needed, it returns the full recording dict)@app.route('/status/<int:recording_id>', methods=['GET'])def get_status(recording_id):- """Endpoint to check the transcription status."""+ """Endpoint to check the transcription/summarization status."""try:recording = db.session.get(Recording, recording_id)if not recording:return jsonify({'error': 'Recording not found'}), 404-- # Return the full recording data, including status and transcription (if available)return jsonify(recording.to_dict())-except Exception as e:app.logger.error(f"Error fetching status for recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500-+# Get Audio Endpoint (no changes needed)@app.route('/audio/<int:recording_id>')def get_audio(recording_id):try:recording = db.session.get(Recording, recording_id)if not recording or not recording.audio_path:return jsonify({'error': 'Recording or audio file not found'}), 404- # Ensure the file actually exists before trying to send itif not os.path.exists(recording.audio_path):- return jsonify({'error': 'Audio file missing from server'}), 404+ app.logger.error(f"Audio file missing from server: {recording.audio_path}")+ return jsonify({'error': 'Audio file missing from server'}), 404return send_file(recording.audio_path)except Exception as e:app.logger.error(f"Error serving audio for recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500+# Delete Recording Endpoint (no changes needed functionally)@app.route('/recording/<int:recording_id>', methods=['DELETE'])def delete_recording(recording_id):try:@@ -316,15 +489,14 @@ def delete_recording(recording_id):try:if recording.audio_path and os.path.exists(recording.audio_path):os.remove(recording.audio_path)- print(f"Deleted audio file: {recording.audio_path}")+ app.logger.info(f"Deleted audio file: {recording.audio_path}")except Exception as e:- # Log error but proceed to delete DB recordapp.logger.error(f"Error deleting audio file {recording.audio_path}: {e}")# Delete the database recorddb.session.delete(recording)db.session.commit()- print(f"Deleted recording record ID: {recording_id}")+ app.logger.info(f"Deleted recording record ID: {recording_id}")return jsonify({'success': True})except Exception as e:@@ -332,10 +504,12 @@ def delete_recording(recording_id):app.logger.error(f"Error deleting recording {recording_id}: {e}")return jsonify({'error': str(e)}), 500+if __name__ == '__main__':- # Use waitress or gunicorn in production instead of Flask's dev server- # Example: waitress-serve --host 0.0.0.0 --port 8899 app:app- app.run(host='0.0.0.0', port=8899, debug=True) # debug=True reloads, which can interfere with threads. Set False for testing threads properly. Consider waitress for better threading.+ # Consider using waitress or gunicorn for production+ # waitress-serve --host 0.0.0.0 --port 8899 app:app+ # For development:+ app.run(host='0.0.0.0', port=8899, debug=True) # Set debug=False if thread issues arise```@@ -422,6 +596,7 @@ flask-sqlalchemy==3.1.1openai==1.3.0werkzeug==2.3.7gunicorn==21.2.0+python-dotenv==1.0.0```@@ -439,51 +614,59 @@ gunicorn==21.2.0<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"><style>- /* Add a subtle transition for dragover effect */- .drag-area {- transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;- }- /* Custom scrollbar for webkit browsers (optional) */- .custom-scrollbar::-webkit-scrollbar {- width: 8px;- }- .custom-scrollbar::-webkit-scrollbar-track {- background: #f1f1f1;- border-radius: 10px;- }- .custom-scrollbar::-webkit-scrollbar-thumb {- background: #c5c5c5;- border-radius: 10px;- }- .custom-scrollbar::-webkit-scrollbar-thumb:hover {- background: #a8a8a8;- }- /* Ensure body takes full height for drop zone */- html, body {- height: 100%;- margin: 0;- }- #app {- min-height: 100%;- display: flex;- flex-direction: column;- }- main {- flex-grow: 1;+ /* Existing styles... */+ .drag-area { transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out; }+ .custom-scrollbar::-webkit-scrollbar { width: 8px; }+ .custom-scrollbar::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }+ .custom-scrollbar::-webkit-scrollbar-thumb { background: #c5c5c5; border-radius: 10px; }+ .custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }+ html, body { height: 100%; margin: 0; }+ #app { min-height: 100%; display: flex; flex-direction: column; }+ main { flex-grow: 1; position: relative; }+ .progress-popup { position: fixed; bottom: 1rem; left: 1rem; z-index: 100; transition: all 0.3s ease-in-out; min-width: 300px; }+ .progress-popup.minimized { transform: translateY(calc(100% - 45px)); }+ .progress-list-item { display: grid; grid-template-columns: auto 1fr auto; gap: 0.5rem; align-items: center; }+ /* Add style for summary pre */+ .summary-box {+ background-color: #f9fafb; /* bg-gray-50 */+ padding: 0.75rem; /* p-3 */+ border-radius: 0.375rem; /* rounded */+ border: 1px solid #e5e7eb; /* border-gray-200 */+ min-height: 60px; /* min-h-[60px] or adjust as needed */+ max-height: 20rem; /* Limit height */+ overflow-y: auto;+ white-space: pre-wrap;+ font-family: inherit; /* Use body font */+ font-size: 0.875rem; /* text-sm */+ line-height: 1.25rem;}+ .status-badge {+ display: inline-block;+ padding: 0.125rem 0.5rem; /* px-2 py-0.5 */+ font-size: 0.75rem; /* text-xs */+ font-weight: 600; /* font-semibold */+ border-radius: 9999px; /* rounded-full */+ margin-top: 0.5rem; /* mt-2 */+ }+ .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 */+ .status-completed { color: #065f46; background-color: #d1fae5; } /* text-green-800 bg-green-100 */+ .status-failed { color: #991b1b; background-color: #fee2e2; } /* text-red-800 bg-red-100 */+ .status-pending { color: #57534e; background-color: #f5f5f4; } /* text-stone-700 bg-stone-100 */+</style></head><body class="bg-gray-100"><div id="app" class="container mx-auto px-4 sm:px-6 lg:px-8 py-6 flex flex-col"><header class="flex justify-between items-center mb-6 pb-4 border-b border-gray-200">- <h1 class="text-3xl font-bold text-gray-800 cursor-pointer" @click="switchToGalleryView" title="Go to Gallery">- Audio Transcription+ <h1 class="text-3xl font-bold text-gray-800 cursor-pointer" @click="switchToGalleryView" title="Go to Gallery">+ Audio Transcription & Summary</h1><div><button @click="switchToUploadView" class="px-4 py-2 mr-2 bg-blue-600 text-white rounded-lg shadow hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition duration-150 ease-in-out"><i class="fas fa-plus mr-1"></i> New Recording</button>- <button+ <button@click="switchToGalleryView":class="{'bg-white text-gray-700 border border-gray-300': currentView !== 'gallery',@@ -496,7 +679,7 @@ gunicorn==21.2.0</header><div v-if="globalError" class="mb-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg" role="alert">- <div class="flex justify-between items-center">+ <div class="flex justify-between items-center"><div><strong class="font-bold">Error:</strong><span class="block sm:inline ml-2">${ globalError }</span>@@ -505,35 +688,32 @@ gunicorn==21.2.0</div></div>- <main class="flex-grow">-- <div v-if="currentView === 'gallery'"- class="flex-grow flex flex-col rounded-lg drag-area"- @dragover.prevent="dragover = true"- @dragleave.prevent="dragover = false"- @drop.prevent="handleDrop"- :class="{'bg-blue-50 border-2 border-dashed border-blue-400': dragover, 'bg-transparent border-2 border-transparent': !dragover}">+ <main class="flex-grow"+ @dragover.prevent="dragover = true"+ @dragleave.prevent="handleDragLeave"+ @drop.prevent="handleDrop">- <div v-if="dragover" class="absolute inset-0 flex items-center justify-center bg-blue-500 bg-opacity-20 z-10 rounded-lg pointer-events-none">- <div class="text-center p-6 bg-white rounded-lg shadow-xl">- <i class="fas fa-upload text-4xl text-blue-500 mb-3"></i>- <p class="text-xl font-semibold text-gray-700">Drop audio file here to upload</p>- </div>+ <div v-if="dragover" class="absolute inset-0 flex items-center justify-center bg-blue-500 bg-opacity-20 z-10 rounded-lg pointer-events-none border-4 border-dashed border-blue-600">+ <div class="text-center p-6 bg-white rounded-lg shadow-xl">+ <i class="fas fa-upload text-4xl text-blue-500 mb-3"></i>+ <p class="text-xl font-semibold text-gray-700">Drop audio file(s) here to upload</p></div>+ </div>- <div class="grid grid-cols-1 lg:grid-cols-4 gap-6 flex-grow">+ <div v-if="currentView === 'gallery'" class="flex-grow flex flex-col rounded-lg">+ <div class="grid grid-cols-1 lg:grid-cols-4 gap-6 flex-grow"><div class="lg:col-span-1 bg-white p-4 rounded-lg shadow-md flex flex-col"><h3 class="text-lg font-semibold mb-4 sticky top-0 bg-white pb-3 border-b border-gray-200">Recordings</h3>- <div v-if="isLoadingRecordings" class="text-center text-gray-500 py-4">+ <div v-if="isLoadingRecordings" class="text-center text-gray-500 py-4"><i class="fas fa-spinner fa-spin mr-2"></i> Loading recordings...</div>- <div v-else-if="recordings.length === 0" class="text-center text-gray-500 py-4 flex-grow flex flex-col items-center justify-center">+ <div v-else-if="recordings.length === 0 && uploadQueue.length === 0" class="text-center text-gray-500 py-4 flex-grow flex flex-col items-center justify-center"><i class="fas fa-folder-open text-4xl text-gray-400 mb-3"></i><p>No recordings yet.</p>- <p>Upload one or drag & drop here!</p>- </div>+ <p>Upload one or drag & drop anywhere!</p>+ </div><div v-else class="space-y-4 overflow-y-auto custom-scrollbar flex-grow pr-1">- <div v-for="group in groupedRecordings" :key="group.title" class="mb-3">+ <div v-for="group in groupedRecordings" :key="group.title" class="mb-3"><h4 class="font-medium text-gray-500 text-xs uppercase tracking-wider mb-2 sticky top-0 bg-white py-1">${ group.title }</h4><ul class="space-y-1"><li v-for="recording in group.items"@@ -544,21 +724,27 @@ gunicorn==21.2.0'bg-blue-100 hover:bg-blue-200 ring-1 ring-blue-300': selectedRecording?.id === recording.id,'hover:bg-gray-100': selectedRecording?.id !== recording.id}">- <div class="flex items-center overflow-hidden mr-2">+ <div class="flex items-center overflow-hidden mr-2"><i class="fas fa-file-audio text-blue-500 mr-2 flex-shrink-0"></i>- <span class="text-sm font-medium text-gray-800 truncate">${ recording.title }</span>+ <span class="text-sm font-medium text-gray-800 truncate" :title="recording.title || 'Loading title...'">${ recording.title || '(Processing...)' }</span></div><div class="flex space-x-2 flex-shrink-0 items-center">- <span v-if="recording.status === 'PROCESSING' || recording.status === 'PENDING'" class="text-xs text-blue-600 italic flex items-center" title="Processing...">- <i class="fas fa-spinner fa-spin mr-1"></i> Processing+ <span v-if="recording.status === 'PROCESSING'" class="text-xs text-blue-600 italic flex items-center" title="Transcribing...">+ <i class="fas fa-spinner fa-spin mr-1"></i> Transcribing+ </span>+ <span v-else-if="recording.status === 'SUMMARIZING'" class="text-xs text-amber-600 italic flex items-center" title="Generating Summary...">+ <i class="fas fa-spinner fa-spin mr-1"></i> Summarizing</span>- <span v-else-if="recording.status === 'FAILED'" class="text-xs text-red-600 italic flex items-center" title="Transcription Failed">+ <span v-else-if="recording.status === 'PENDING'" class="text-xs text-gray-500 italic flex items-center" title="Waiting...">+ <i class="fas fa-clock mr-1"></i> Pending+ </span>+ <span v-else-if="recording.status === 'FAILED'" class="text-xs text-red-600 italic flex items-center" title="Processing Failed"><i class="fas fa-exclamation-triangle mr-1"></i> Failed</span>- <span v-else-if="recording.status === 'COMPLETED'" class="text-xs text-green-600" title="Completed">+ <span v-else-if="recording.status === 'COMPLETED'" class="text-xs text-green-600" title="Completed"><i class="fas fa-check-circle"></i></span>- <button @click.stop="editRecording(recording)" class="text-gray-500 hover:text-blue-600 text-xs p-1 rounded hover:bg-gray-200" title="Edit Details">+ <button @click.stop="editRecording(recording)" class="text-gray-500 hover:text-blue-600 text-xs p-1 rounded hover:bg-gray-200" title="Edit Details"><i class="fas fa-edit"></i></button><button @click.stop="confirmDelete(recording)" class="text-gray-500 hover:text-red-600 text-xs p-1 rounded hover:bg-gray-200" title="Delete Recording">@@ -571,17 +757,17 @@ gunicorn==21.2.0</div></div>- <div class="lg:col-span-3 bg-white p-6 rounded-lg shadow-md flex flex-col">- <div v-if="selectedRecording" class="flex-grow">+ <div class="lg:col-span-3 bg-white p-6 rounded-lg shadow-md flex flex-col">+ <div v-if="selectedRecording" class="flex-grow flex flex-col"><div class="flex flex-col sm:flex-row justify-between items-start mb-4 border-b border-gray-200 pb-4">- <div class="mb-3 sm:mb-0">- <h3 class="text-2xl font-semibold text-gray-900">${ selectedRecording.title }</h3>+ <div class="mb-3 sm:mb-0 max-w-lg">+ <h3 class="text-2xl font-semibold text-gray-900">${ selectedRecording.title || 'Loading...' }</h3><p class="text-sm text-gray-500 mt-1">Created: ${ new Date(selectedRecording.created_at).toLocaleString() } | Size: ${ formatFileSize(selectedRecording.file_size) }</p>- <span v-if="selectedRecording.status === 'PROCESSING' || selectedRecording.status === 'PENDING'" class="mt-2 inline-block px-2 py-0.5 text-xs font-semibold text-blue-800 bg-blue-100 rounded-full">Status: Processing</span>- <span v-else-if="selectedRecording.status === 'FAILED'" class="mt-2 inline-block px-2 py-0.5 text-xs font-semibold text-red-800 bg-red-100 rounded-full">Status: Failed</span>- <span v-else-if="selectedRecording.status === 'COMPLETED'" class="mt-2 inline-block px-2 py-0.5 text-xs font-semibold text-green-800 bg-green-100 rounded-full">Status: Completed</span>+ <span :class="getStatusClass(selectedRecording.status)" class="status-badge">+ Status: ${ formatStatus(selectedRecording.status) }+ </span></div><div class="flex space-x-2 flex-shrink-0"><button @click="editRecording(selectedRecording)" class="px-3 py-1.5 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm shadow-sm">@@ -592,141 +778,98 @@ gunicorn==21.2.0</button></div></div>- <div class="grid md:grid-cols-2 gap-6">- <div>- <h4 class="font-semibold text-gray-700 mb-2">Transcription</h4>- <div v-if="selectedRecording.status === 'COMPLETED'" class="h-96 overflow-y-auto p-4 bg-gray-50 rounded border border-gray-200 text-sm custom-scrollbar">- <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'No transcription available.' }</pre>- </div>- <div v-else-if="selectedRecording.status === 'FAILED'" class="h-96 overflow-y-auto p-4 bg-red-50 rounded border border-red-200 text-sm text-red-700 custom-scrollbar">- <p class="font-medium mb-2">Transcription Failed:</p>- <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'An unknown error occurred.' }</pre>- </div>- <div v-else class="h-96 flex items-center justify-center p-4 bg-gray-50 rounded border border-gray-200 text-gray-500">- <i class="fas fa-spinner fa-spin mr-2"></i> Transcription in progress...++ <div class="grid md:grid-cols-2 gap-6 flex-grow overflow-hidden">+ <div class="flex flex-col overflow-hidden">+ <h4 class="font-semibold text-gray-700 mb-2 flex-shrink-0">Transcription</h4>+ <div class="flex-grow overflow-y-auto p-4 bg-gray-50 rounded border border-gray-200 text-sm custom-scrollbar">+ <div v-if="selectedRecording.status === 'COMPLETED' || selectedRecording.status === 'SUMMARIZING'">+ <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'No transcription available.' }</pre>+ </div>+ <div v-else-if="selectedRecording.status === 'FAILED'" class="text-red-700">+ <p class="font-medium mb-2">Processing Failed:</p>+ <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'An unknown error occurred.' }</pre>+ </div>+ <div v-else class="flex items-center justify-center text-gray-500 h-full">+ <i class="fas fa-spinner fa-spin mr-2"></i> Transcription in progress...+ </div></div></div>- <div class="space-y-4">++ <div class="flex flex-col space-y-4 overflow-hidden"><div><h4 class="font-semibold text-gray-700 mb-2">Audio Player</h4><audio controls class="w-full" :key="selectedRecording.id" :src="'/audio/' + selectedRecording.id">Your browser does not support the audio element.</audio></div>++ <div class="flex flex-col overflow-hidden">+ <h4 class="font-semibold text-gray-700 mb-2 flex-shrink-0">Summary</h4>+ <div class="flex-grow overflow-hidden">+ <div v-if="selectedRecording.status === 'COMPLETED'" class="summary-box custom-scrollbar">+ ${ selectedRecording.summary || 'No summary generated.' }+ </div>+ <div v-else-if="selectedRecording.status === 'FAILED'" class="summary-box text-red-700 custom-scrollbar">+ ${ selectedRecording.summary || 'Summary generation failed or was skipped.' }+ </div>+ <div v-else class="h-24 flex items-center justify-center p-4 bg-gray-50 rounded border border-gray-200 text-gray-500">+ <i class="fas fa-spinner fa-spin mr-2"></i> Summary pending...+ </div>+ </div>+ </div>+<div><h4 class="font-semibold text-gray-700 mb-1">Participants</h4><p class="text-sm bg-gray-50 p-3 rounded border border-gray-200 min-h-[40px]">${ selectedRecording.participants || 'None specified' }</p></div>- <div>- <h4 class="font-semibold text-gray-700 mb-1">Notes</h4>- <pre class="text-sm bg-gray-50 p-3 rounded border border-gray-200 whitespace-pre-wrap h-40 overflow-y-auto custom-scrollbar font-sans">${ selectedRecording.notes || 'No notes' }</pre>+ <div class="flex flex-col overflow-hidden flex-grow">+ <h4 class="font-semibold text-gray-700 mb-1 flex-shrink-0">Notes</h4>+ <div class="flex-grow overflow-hidden">+ <pre class="text-sm bg-gray-50 p-3 rounded border border-gray-200 whitespace-pre-wrap h-40 overflow-y-auto custom-scrollbar font-sans">${ selectedRecording.notes || 'No notes' }</pre>+ </div></div></div></div>- </div>- <div v-else class="flex flex-col items-center justify-center text-center text-gray-500 flex-grow">+ </div>+ <div v-else class="flex flex-col items-center justify-center text-center text-gray-500 flex-grow"><i class="fas fa-hand-pointer text-4xl text-gray-400 mb-4"></i><p class="text-lg font-medium mb-2">Select a recording from the list to view details.</p>- <p>Or, drag and drop an audio file anywhere on this page to upload.</p>+ <p>Or, drag and drop audio file(s) anywhere on this page to upload.</p></div></div></div></div>- <div v-if="currentView === 'upload'"+ <div v-if="currentView === 'upload'"class="flex-grow flex items-center justify-center p-4">- <div class="w-full max-w-lg bg-white p-8 rounded-xl shadow-lg border border-gray-200 text-center"- @dragover.prevent="dragover = true"- @dragleave.prevent="dragover = false"- @drop.prevent="handleDrop"+ <div class="w-full max-w-lg bg-white p-8 rounded-xl shadow-lg border border-gray-200 text-center drag-area":class="{'border-blue-500 bg-blue-50': dragover}">-- <div v-if="isProcessing" class="space-y-4 py-8">- <div class="animate-spin mx-auto h-12 w-12">- <i class="fas fa-circle-notch text-4xl text-blue-500"></i>- </div>- <h2 class="text-xl font-semibold text-gray-700 mb-2">Processing your audio...</h2>- <p class="text-sm text-gray-600">${ processingStatus.message }</p>- <div class="w-full bg-gray-200 rounded-full h-2.5 mt-4 max-w-sm mx-auto">- <div class="bg-blue-600 h-2.5 rounded-full transition-all duration-300" :style="{ width: processingStatus.progress + '%' }"></div>- </div>- </div>-- <div v-else class="py-8">+ <div class="py-8"><i class="fas fa-cloud-upload-alt text-5xl mb-5 text-blue-500"></i>- <h2 class="text-xl font-semibold text-gray-700 mb-2">Upload New Recording</h2>- <p class="text-gray-500 mb-4">Drag & drop your audio file here or click below.</p>- <input type="file" @change="handleFileSelect" accept="audio/*" class="hidden" ref="fileInput">+ <h2 class="text-xl font-semibold text-gray-700 mb-2">Upload New Recordings</h2>+ <p class="text-gray-500 mb-4">Drag & drop your audio files here or click below.</p>+ <input type="file" @change="handleFileSelect" accept="audio/*" class="hidden" ref="fileInput" multiple><button @click="$refs.fileInput.click()" class="mt-4 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 shadow-sm transition duration-150 ease-in-out">- <i class="fas fa-file-import mr-2"></i> Select File+ <i class="fas fa-file-import mr-2"></i> Select Files</button>- <p class="text-xs text-gray-400 mt-4">Max file size: ${ maxFileSizeMB } MB</p>- </div>- </div>- </div>--- <div v-if="currentView === 'input' && currentRecording" class="bg-white p-6 md:p-8 rounded-lg shadow-md border border-gray-200">- <div class="flex justify-between items-center mb-6 pb-4 border-b border-gray-200">- <h2 class="text-2xl font-semibold text-gray-800">Transcription Complete</h2>- <button @click="switchToGalleryView" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition duration-150 ease-in-out">- <i class="fas fa-arrow-left mr-2"></i> Back to Gallery- </button>- </div>- <div class="grid md:grid-cols-2 gap-8">- <div>- <h3 class="text-lg font-semibold text-gray-700 mb-3">Transcription</h3>- <div class="h-96 overflow-y-auto p-4 bg-gray-50 rounded border border-gray-200 text-sm custom-scrollbar">- <pre class="whitespace-pre-wrap font-sans">${ currentRecording.transcription || 'Transcription not available.' }</pre>- </div>- </div>- <div>- <h3 class="text-lg font-semibold text-gray-700 mb-3">Add Recording Details</h3>- <div class="space-y-4">- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Title</label>- <input v-model="currentRecording.title"- @input="autoSave"- placeholder="Enter a title for this recording"- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50">- </div>- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Participants</label>- <input v-model="currentRecording.participants"- @input="autoSave"- placeholder="e.g., John Doe, Jane Smith"- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50">- </div>- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label>- <textarea v-model="currentRecording.notes"- @input="autoSave"- placeholder="Add any relevant notes here..."- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50"- rows="5"></textarea>- </div>- <div class="text-sm text-gray-500 pt-2">- <p>File Size: ${ formatFileSize(currentRecording.file_size) }</p>- <p>Created: ${ new Date(currentRecording.created_at).toLocaleString() }</p>- <p class="text-green-600 font-medium mt-2">Details are auto-saved.</p>- </div>- </div>+ <p class="text-xs text-gray-400 mt-4">Max file size per file: ${ maxFileSizeMB } MB</p></div></div></div>- </main>+ </main>- <footer class="text-center py-4 mt-8 text-xs text-gray-400 border-t border-gray-200">+ <footer class="text-center py-4 mt-8 text-xs text-gray-400 border-t border-gray-200">Audio Transcription App © ${ new Date().getFullYear() }- </footer>+ </footer>- <div v-if="showEditModal" class="fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4">- <div class="bg-white p-6 rounded-lg shadow-xl w-full max-w-lg max-h-[90vh] overflow-y-auto">+ <div v-if="showEditModal" class="fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4">+ <div class="bg-white p-6 rounded-lg shadow-xl w-full max-w-lg max-h-[90vh] overflow-y-auto custom-scrollbar"><div class="flex justify-between items-center mb-4">- <h3 class="text-xl font-semibold text-gray-800">Edit Recording Details</h3>- <button @click="cancelEdit" class="text-gray-400 hover:text-gray-600">×</button>- </div>+ <h3 class="text-xl font-semibold text-gray-800">Edit Recording Details</h3>+ <button @click="cancelEdit" class="text-gray-400 hover:text-gray-600 text-2xl leading-none">×</button>+ </div><div v-if="editingRecording" class="space-y-4"><div><label class="block text-sm font-medium text-gray-700 mb-1">Title</label>@@ -735,13 +878,17 @@ gunicorn==21.2.0<div><label class="block text-sm font-medium text-gray-700 mb-1">Participants</label><input v-model="editingRecording.participants" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50">+ </div>+ <div>+ <label class="block text-sm font-medium text-gray-700 mb-1">Summary</label>+ <textarea v-model="editingRecording.summary" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50" rows="5"></textarea></div><div><label class="block text-sm font-medium text-gray-700 mb-1">Notes</label><textarea v-model="editingRecording.notes" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50" rows="4"></textarea></div><div class="flex justify-end space-x-3 pt-4">- <button @click="cancelEdit" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Cancel</button>+ <button @click="cancelEdit" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Cancel</button><button @click="saveEdit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Save Changes</button></div></div>@@ -749,65 +896,128 @@ gunicorn==21.2.0</div><div v-if="showDeleteModal" class="fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4">- <div class="bg-white p-6 rounded-lg shadow-xl max-w-md w-full">+ <div class="bg-white p-6 rounded-lg shadow-xl max-w-md w-full"><h3 class="text-lg font-semibold text-gray-800 mb-4">Confirm Delete</h3>- <p v-if="recordingToDelete" class="mb-2 text-gray-600">Are you sure you want to permanently delete the recording titled "<strong>${ recordingToDelete.title }</strong>"?</p>- <p class="text-sm text-red-600 mb-6">This action cannot be undone and will delete both the record and the audio file.</p>+ <p v-if="recordingToDelete" class="mb-2 text-gray-600">Are you sure you want to permanently delete the recording titled "<strong>${ recordingToDelete.title }</strong>"?</p>+ <p class="text-sm text-red-600 mb-6">This action cannot be undone and will delete the record, transcription, summary, and the audio file.</p><div class="flex justify-end space-x-3"><button @click="cancelDelete" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Cancel</button><button @click="deleteRecording" class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700">Delete Permanently</button></div></div></div>- </div>- <script>+ <div v-if="uploadQueue.length > 0 || currentlyProcessingFile"+ class="progress-popup bg-white rounded-lg shadow-xl border border-gray-200 overflow-hidden"+ :class="{ 'minimized': progressPopupMinimized }">++ <div class="flex justify-between items-center p-2 bg-gray-100 border-b border-gray-200 cursor-pointer" @click="progressPopupMinimized = !progressPopupMinimized">+ <h4 class="text-sm font-semibold text-gray-700">+ <i class="fas fa-upload mr-2 text-blue-500"></i>+ Upload & Process Progress (${ completedInQueue }/${ totalInQueue } completed)+ </h4>+ <button class="text-gray-500 hover:text-gray-700">+ <i :class="progressPopupMinimized ? 'fa-chevron-up' : 'fa-chevron-down'" class="fas fa-fw"></i>+ </button>+ </div>++ <div class="p-3 max-h-60 overflow-y-auto custom-scrollbar" v-show="!progressPopupMinimized">+ <div v-if="currentlyProcessingFile" class="mb-3 pb-3 border-b border-dashed border-gray-200">+ <div class="flex items-center justify-between mb-1">+ <p class="text-xs font-medium text-gray-800 truncate mr-2" :title="currentlyProcessingFile.file.name">+ <i class="fas fa-spinner fa-spin text-blue-500 mr-1"></i> Processing: ${ currentlyProcessingFile.file.name }+ </p>+ <span class="text-xs text-gray-500 flex-shrink-0">${ formatFileSize(currentlyProcessingFile.file.size) }</span>+ </div>+ <p class="text-xs text-gray-600 mb-1 italic">${ processingMessage }</p>+ <div class="w-full bg-gray-200 rounded-full h-1.5">+ <div class="bg-blue-500 h-1.5 rounded-full transition-all duration-300" :style="{ width: processingProgress + '%' }"></div>+ </div>+ </div>++ <div v-if="queuedFiles.length > 0" class="mb-2">+ <p class="text-xs font-semibold text-gray-500 mb-1">${ queuedFiles.length } file(s) queued:</p>+ <ul class="space-y-1">+ <li v-for="item in queuedFiles" :key="item.clientId" class="text-xs text-gray-600 progress-list-item">+ <i class="fas fa-clock text-gray-400 fa-fw"></i>+ <span class="truncate" :title="item.file.name">${ item.file.name }</span>+ <span class="text-gray-400 flex-shrink-0">${ formatFileSize(item.file.size) }</span>+ </li>+ </ul>+ </div>++ <div v-if="finishedFilesInQueue.length > 0" class="mt-2 pt-2 border-t border-dashed border-gray-200">+ <p class="text-xs font-semibold text-gray-500 mb-1">Recently finished:</p>+ <ul class="space-y-1">+ <li v-for="item in finishedFilesInQueue.slice(-5)" :key="item.clientId" class="text-xs progress-list-item">+ <i v-if="item.status === 'completed'" class="fas fa-check-circle text-green-500 fa-fw"></i>+ <i v-else-if="item.status === 'failed'" class="fas fa-exclamation-triangle text-red-500 fa-fw"></i>+ <i v-else class="fas fa-question-circle text-gray-400 fa-fw"></i>+ <span class="truncate" :title="item.file.name">${ item.file.name }</span>+ <span v-if="item.status === 'failed'" class="text-red-500 text-xs italic flex-shrink-0">Failed</span>+ <span v-else class="text-gray-400 flex-shrink-0">${ formatFileSize(item.file.size) }</span>+ </li>+ </ul>+ </div>++ <div v-if="uploadQueue.length > 0 && queuedFiles.length === 0 && !currentlyProcessingFile" class="text-xs text-center text-gray-500 py-2">+ All uploads processed.+ </div>+ </div>+ </div>++ </div> <script>const { createApp, ref, reactive, computed, onMounted, watch, nextTick } = VuecreateApp({setup() {- const currentView = ref('gallery'); // Default view is now gallery+ const currentView = ref('gallery');const dragover = ref(false);- const currentRecording = ref(null); // For the input view after upload- const recordings = ref([]); // Full list for gallery- const selectedRecording = ref(null); // For gallery detail view+ const recordings = ref([]);+ const selectedRecording = ref(null);+ // const currentRecording = ref(null); // Less used now with modal editing++ // --- Multi-Upload State ---+ // Status: 'queued'|'uploading'|'processing'|'summarizing'|'completed'|'failed'+ const uploadQueue = ref([]);+ const currentlyProcessingFile = ref(null);+ const processingProgress = ref(0);+ const processingMessage = ref('');+ const isProcessingActive = ref(false);+ const pollInterval = ref(null);+ const progressPopupMinimized = ref(false);+const showEditModal = ref(false);const showDeleteModal = ref(false);- const editingRecording = ref(null);+ const editingRecording = ref(null); // Holds a *copy* for the modalconst recordingToDelete = ref(null);- const autoSaveTimeout = ref(null);- const isProcessing = ref(false); // Upload/processing spinner- const isLoadingRecordings = ref(true); // Loading state for gallery list- const processingStatus = reactive({ progress: 0, message: '' });- const pollInterval = ref(null);+ // const autoSaveTimeout = ref(null); // Autosave not implemented for modal+ const isLoadingRecordings = ref(true);const globalError = ref(null);- const maxFileSizeMB = ref(250); // Set your max file size here+ const maxFileSizeMB = ref(250); // Default, could fetch from config if needed// --- Computed Properties ---const groupedRecordings = computed(() => {- // Sort recordings newest first before groupingconst sortedRecordings = [...recordings.value].sort((a, b) => new Date(b.created_at) - new Date(a.created_at));-+ // Grouping logic (same as before)...const groups = { today: [], yesterday: [], thisWeek: [], older: [] };const now = new Date();const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());const yesterdayStart = new Date(todayStart);yesterdayStart.setDate(todayStart.getDate() - 1);- // Consider locale for start of week if needed- const currentDayOfWeek = now.getDay(); // 0 = Sunday, 1 = Monday, ...- const daysToSubtract = currentDayOfWeek === 0 ? 6 : currentDayOfWeek -1; // Assuming Monday is start+ const currentDayOfWeek = now.getDay();+ const daysToSubtract = currentDayOfWeek === 0 ? 6 : currentDayOfWeek - 1;const weekStart = new Date(todayStart);weekStart.setDate(todayStart.getDate() - daysToSubtract);sortedRecordings.forEach(r => {- const date = new Date(r.created_at);+ const date = new Date(r.created_at);if (date >= todayStart) groups.today.push(r);else if (date >= yesterdayStart) groups.yesterday.push(r);else if (date >= weekStart) groups.thisWeek.push(r);else groups.older.push(r);});-- return [+ return [{ title: 'Today', items: groups.today },{ title: 'Yesterday', items: groups.yesterday },{ title: 'This Week', items: groups.thisWeek },@@ -815,213 +1025,327 @@ gunicorn==21.2.0].filter(g => g.items.length > 0);});+ const totalInQueue = computed(() => uploadQueue.value.length);+ const completedInQueue = computed(() => uploadQueue.value.filter(item => item.status === 'completed' || item.status === 'failed').length);+ const queuedFiles = computed(() => uploadQueue.value.filter(item => item.status === 'queued'));+ // Filter finished: includes completed and failed+ const finishedFilesInQueue = computed(() => uploadQueue.value.filter(item => ['completed', 'failed'].includes(item.status)));++// --- Methods ---const setGlobalError = (message, duration = 7000) => {- globalError.value = message;+ globalError.value = message;if (duration > 0) {setTimeout(() => { if (globalError.value === message) globalError.value = null; }, duration);}};const formatFileSize = (bytes) => {- if (bytes == null || bytes === 0) return '0 Bytes'; // Added null check+ if (bytes == null || bytes === 0) return '0 Bytes';const k = 1024;const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];- if (bytes < 0) bytes = 0; // Handle potential negative values if they occur- const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k))); // Ensure i is non-negative- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];+ if (bytes < 0) bytes = 0;+ const i = bytes === 0 ? 0 : Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));+ const size = i === 0 ? bytes : parseFloat((bytes / Math.pow(k, i)).toFixed(2));+ return size + ' ' + sizes[i];};- const resetProcessingState = () => {- isProcessing.value = false;- dragover.value = false;- processingStatus.message = '';- processingStatus.progress = 0;- if (pollInterval.value) {- clearInterval(pollInterval.value);- pollInterval.value = null;+ // Helper for status display+ const formatStatus = (status) => {+ if (!status) return 'Unknown';+ // Capitalize first letter, handle 'SUMMARIZING' specifically+ return status.charAt(0).toUpperCase() + status.slice(1).toLowerCase();+ };++ // Helper for status badge class+ const getStatusClass = (status) => {+ switch(status) {+ case 'PENDING': return 'status-pending';+ case 'PROCESSING': return 'status-processing';+ case 'SUMMARIZING': return 'status-summarizing';+ case 'COMPLETED': return 'status-completed';+ case 'FAILED': return 'status-failed';+ default: return 'status-pending'; // Default or unknown}- };+ };+- const switchToUploadView = () => {- resetProcessingState();+ const resetCurrentFileProcessingState = () => {+ if (pollInterval.value) clearInterval(pollInterval.value);+ pollInterval.value = null;+ currentlyProcessingFile.value = null;+ processingProgress.value = 0;+ processingMessage.value = '';+ };++ const switchToUploadView = () => {currentView.value = 'upload';selectedRecording.value = null;- currentRecording.value = null;- };+ };const switchToGalleryView = async () => {- resetProcessingState();currentView.value = 'gallery';- selectedRecording.value = null; // Keep selection or clear? Let's clear for consistency.- currentRecording.value = null;- await loadRecordings(); // Refresh recordings when explicitly switching+ await loadRecordings(); // Refresh recordings when switching back};- const handleDrop = (e) => {- dragover.value = false; // Ensure dragover state is reset- const file = e.dataTransfer.files[0];- if (file && file.type.startsWith('audio/')) {- uploadFile(file);- } else if (file) {- setGlobalError('Invalid file type. Please upload an audio file.');+ const handleDragLeave = (e) => {+ if (e.relatedTarget && e.currentTarget.contains(e.relatedTarget)) {+ return;}- };+ dragover.value = false;+ }++ const handleDrop = (e) => {+ dragover.value = false;+ addFilesToQueue(e.dataTransfer.files);+ };const handleFileSelect = (e) => {- const file = e.target.files[0];- if (file) {- uploadFile(file);- }+ addFilesToQueue(e.target.files);e.target.value = null; // Reset input};- const uploadFile = async (file) => {- globalError.value = null;- resetProcessingState(); // Clear previous state before new upload- isProcessing.value = true; // Set processing true for the specific upload view spinner- currentView.value = 'upload'; // Switch to upload view to show progress indicator centrally- await nextTick(); // Ensure view updates before fetch starts-- processingStatus.message = 'Preparing upload...';- processingStatus.progress = 5;-- // Check file size client-side (optional but good UX)- if (file.size > maxFileSizeMB.value * 1024 * 1024) {- setGlobalError(`File exceeds the maximum size of ${maxFileSizeMB.value} MB.`);- resetProcessingState();- currentView.value = 'gallery'; // Go back to gallery after error+ // --- Queue Management ---+ const addFilesToQueue = (files) => {+ let filesAdded = 0;+ for (const file of files) {+ if (file && file.type.startsWith('audio/')) {+ if (file.size > maxFileSizeMB.value * 1024 * 1024) {+ setGlobalError(`File "${file.name}" exceeds the maximum size of ${maxFileSizeMB.value} MB and was skipped.`);+ continue;+ }+ const clientId = `client-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;+ uploadQueue.value.push({+ file: file, status: 'queued', recordingId: null, clientId: clientId, error: null+ });+ filesAdded++;+ } else if (file) {+ setGlobalError(`Invalid file type "${file.name}". Only audio files are accepted. File skipped.`);+ }+ }+ if(filesAdded > 0) {+ console.log(`Added ${filesAdded} file(s) to the queue.`);+ progressPopupMinimized.value = false; // Show popup+ if (!isProcessingActive.value) {+ startProcessingQueue();+ }+ }+ };++ const startProcessingQueue = async () => {+ console.log("Attempting to start processing queue...");+ if (isProcessingActive.value) {+ console.log("Queue processor already active.");return;- }+ }- const formData = new FormData();- formData.append('file', file);+ isProcessingActive.value = true;+ resetCurrentFileProcessingState();- try {- processingStatus.message = 'Uploading file...';- processingStatus.progress = 10;+ const nextFileItem = uploadQueue.value.find(item => item.status === 'queued');- const response = await fetch('/upload', { method: 'POST', body: formData });- const data = await response.json();+ if (nextFileItem) {+ console.log(`Processing next file: ${nextFileItem.file.name} (Client ID: ${nextFileItem.clientId})`);+ currentlyProcessingFile.value = nextFileItem;+ nextFileItem.status = 'uploading';+ processingMessage.value = 'Preparing upload...';+ processingProgress.value = 5;- if (!response.ok) {- if (response.status === 413) throw new Error(data.error || `File too large. Maximum size: ${data.max_size_mb?.toFixed(0) || maxFileSizeMB.value} MB.`);- throw new Error(data.error || `Upload failed with status ${response.status}`);- }+ try {+ const formData = new FormData();+ formData.append('file', nextFileItem.file);- if (response.status === 202 && data.id) {- processingStatus.message = 'Upload complete. Starting transcription...';- processingStatus.progress = 30;+ processingMessage.value = 'Uploading file...';+ processingProgress.value = 10;- // Add to recordings list immediately for gallery view update- recordings.value.unshift(data);+ const response = await fetch('/upload', { method: 'POST', body: formData });+ const data = await response.json();- // Start polling- pollProcessingStatus(data.id);- } else {- throw new Error('Unexpected success response from server after upload.');- }+ if (!response.ok) {+ let errorMsg = data.error || `Upload failed with status ${response.status}`;+ if (response.status === 413) errorMsg = data.error || `File too large. Max: ${data.max_size_mb?.toFixed(0) || maxFileSizeMB.value} MB.`;+ throw new Error(errorMsg);+ }- } catch (error) {- console.error('Upload Error:', error);- setGlobalError(`Upload failed: ${error.message}`);- resetProcessingState();- currentView.value = 'gallery'; // Go back to gallery on error+ if (response.status === 202 && data.id) {+ console.log(`File ${nextFileItem.file.name} uploaded. Recording ID: ${data.id}. Starting status poll.`);+ // Status is now 'PENDING' on backend, will be updated by poll+ nextFileItem.status = 'pending'; // Reflect initial backend status+ nextFileItem.recordingId = data.id;+ processingMessage.value = 'Upload complete. Waiting for processing...';+ processingProgress.value = 30;++ // Add preliminary record to gallery immediately+ recordings.value.unshift(data);+ // Optionally select the new item+ // selectRecording(data);++ pollProcessingStatus(nextFileItem); // Start polling++ } else {+ throw new Error('Unexpected success response from server after upload.');+ }++ } catch (error) {+ console.error(`Upload/Processing Error for ${nextFileItem.file.name} (Client ID: ${nextFileItem.clientId}):`, error);+ nextFileItem.status = 'failed';+ nextFileItem.error = error.message;+ // Find the potentially added preliminary record and mark it failed+ const failedRecordIndex = recordings.value.findIndex(r => r.id === nextFileItem.recordingId);+ if(failedRecordIndex !== -1) {+ recordings.value[failedRecordIndex].status = 'FAILED';+ recordings.value[failedRecordIndex].transcription = `Upload/Processing failed: ${error.message}`;+ } else {+ // If record wasn't even created, add a note+ setGlobalError(`Failed to process "${nextFileItem.file.name}": ${error.message}`);+ }++ // Reset state and try next file+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue();+ }+ } else {+ console.log("Upload queue is empty or no files are queued.");+ isProcessingActive.value = false;+ // Optional: Auto-minimize popup after a delay+ // setTimeout(() => {+ // if (!isProcessingActive.value && uploadQueue.value.every(f => ['completed', 'failed'].includes(f.status))) {+ // progressPopupMinimized.value = true;+ // }+ // }, 5000);}- };+ };- const pollProcessingStatus = (recordingId) => {- if (pollInterval.value) clearInterval(pollInterval.value); // Clear existing before starting new+ const pollProcessingStatus = (fileItem) => {+ if (pollInterval.value) clearInterval(pollInterval.value);++ const recordingId = fileItem.recordingId;+ if (!recordingId) {+ console.error("Cannot poll status without recording ID for", fileItem.file.name);+ fileItem.status = 'failed';+ fileItem.error = 'Internal error: Missing recording ID for polling.';+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ nextTick(startProcessingQueue); // Try next file+ return;+ }- processingStatus.message = 'Transcription queued...';- processingStatus.progress = 40;+ // Initial message based on fileItem status (should be 'pending' initially)+ processingMessage.value = 'Waiting for transcription...';+ processingProgress.value = 40;pollInterval.value = setInterval(async () => {+ // Check if the item is still the one being processed and hasn't finished/failed+ if (!currentlyProcessingFile.value || currentlyProcessingFile.value.clientId !== fileItem.clientId || ['completed', 'failed'].includes(fileItem.status)) {+ console.log(`Polling stopped for ${fileItem.clientId} as it's no longer active or finished.`);+ clearInterval(pollInterval.value);+ pollInterval.value = null;+ // If this was the active file, allow queue to restart+ if (currentlyProcessingFile.value && currentlyProcessingFile.value.clientId === fileItem.clientId) {+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue();+ }+ return;+ }+try {- console.log(`Polling status for recording ID: ${recordingId}`);+ console.log(`Polling status for recording ID: ${recordingId} (${fileItem.file.name})`);const response = await fetch(`/status/${recordingId}`);if (!response.ok) throw new Error(`Status check failed with status ${response.status}`);const data = await response.json();- const index = recordings.value.findIndex(r => r.id === recordingId);+ const galleryIndex = recordings.value.findIndex(r => r.id === recordingId);// Update item in the main recordings list- if (index !== -1) {- recordings.value[index] = data;+ if (galleryIndex !== -1) {+ recordings.value[galleryIndex] = data;if(selectedRecording.value?.id === recordingId) {selectedRecording.value = data; // Update selection if viewing details}}+ // Update the status in the uploadQueue item as well+ fileItem.status = data.status;++ // Update progress display based on backend statusif (data.status === 'COMPLETED') {- processingStatus.message = 'Transcription complete!';- processingStatus.progress = 100;+ console.log(`Processing COMPLETED for ${fileItem.file.name} (ID: ${recordingId})`);+ processingMessage.value = 'Processing complete!';+ processingProgress.value = 100;+ fileItem.status = 'completed'; // Final status for queue item+ // Stop polling, reset state, and trigger next itemclearInterval(pollInterval.value);pollInterval.value = null;- handleProcessingComplete(data);+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue();+} else if (data.status === 'FAILED') {- processingStatus.message = 'Transcription failed.';- processingStatus.progress = 100; // Show progress done, but failed+ console.log(`Processing FAILED for ${fileItem.file.name} (ID: ${recordingId})`);+ processingMessage.value = 'Processing failed.';+ processingProgress.value = 100; // Show 100% but failed state+ fileItem.status = 'failed'; // Final status for queue item+ fileItem.error = data.transcription || data.summary || 'Processing failed on server.';+ setGlobalError(`Processing failed for "${data.title || fileItem.file.name}".`);+ // Stop polling, reset state, and trigger next itemclearInterval(pollInterval.value);pollInterval.value = null;- setGlobalError(`Transcription failed for "${data.title || 'recording ' + data.id}".`);- isProcessing.value = false; // Stop main processing indicator- currentView.value = 'gallery'; // Ensure user is back in gallery- if (!selectedRecording.value && recordings.value.length > 0) {- // Optionally select the failed item if nothing else is selected- selectRecording(data);- }+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue();+} else if (data.status === 'PROCESSING') {- processingStatus.message = 'Transcription in progress...';- processingStatus.progress = 60 + Math.random() * 20; // Simulate some progress+ processingMessage.value = 'Transcription in progress...';+ processingProgress.value = Math.min(65, processingProgress.value + Math.random() * 5); // Mid-range progress+ } else if (data.status === 'SUMMARIZING') {+ processingMessage.value = 'Generating title & summary...';+ processingProgress.value = Math.min(95, processingProgress.value + Math.random() * 5); // Higher progress} else { // PENDING- processingStatus.message = 'Waiting for transcription to start...';- processingStatus.progress = 45;+ processingMessage.value = 'Waiting in queue...';+ processingProgress.value = 45; // Keep progress indication while pending}} catch (error) {- console.error('Polling Error:', error);+ console.error(`Polling Error for ${fileItem.file.name} (ID: ${recordingId}):`, error);+ // Assume failed if polling error occurs+ fileItem.status = 'failed';+ fileItem.error = `Error checking status: ${error.message}`;+ setGlobalError(`Error checking status for "${fileItem.file.name}": ${error.message}.`);+ // Update record in gallery if found+ const galleryIndex = recordings.value.findIndex(r => r.id === recordingId);+ if (galleryIndex !== -1) recordings.value[galleryIndex].status = 'FAILED';+clearInterval(pollInterval.value);pollInterval.value = null;- setGlobalError(`Error checking transcription status: ${error.message}. Please check the gallery.`);- resetProcessingState();- currentView.value = 'gallery';+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue(); // Process the next file}- }, 4000); // Poll every 4 seconds- };-- const handleProcessingComplete = (recordingData) => {- // Ensure the final data is in the list- const index = recordings.value.findIndex(r => r.id === recordingData.id);- if (index !== -1) recordings.value[index] = recordingData;- else recordings.value.unshift(recordingData); // Add if missing-- currentRecording.value = recordingData; // Set for the input view- resetProcessingState(); // Clear processing state- currentView.value = 'input'; // Switch to the input view- };-- const autoSave = () => {- clearTimeout(autoSaveTimeout.value);- autoSaveTimeout.value = setTimeout(() => {- if (currentView.value === 'input' && currentRecording.value) {- saveMetadata(currentRecording.value);- }- }, 1200); // Save after 1.2 seconds+ }, 5000); // Poll every 5 seconds (adjust as needed)};+ // --- Gallery and Detail Methods ---+ // AutoSave removed in favor of explicit save in modal+ // const autoSave = () => { ... };+const saveMetadata = async (recordingDataToSave) => {- // ...(keep existing saveMetadata logic)...- // Make sure it updates recordings.value[index] and selectedRecording.value if needed- globalError.value = null;+ globalError.value = null;if (!recordingDataToSave || !recordingDataToSave.id) return null;console.log('Saving metadata for:', recordingDataToSave.id);try {const payload = {- id: recordingDataToSave.id,- title: recordingDataToSave.title,- participants: recordingDataToSave.participants,- notes: recordingDataToSave.notes- };+ id: recordingDataToSave.id,+ title: recordingDataToSave.title,+ participants: recordingDataToSave.participants,+ notes: recordingDataToSave.notes,+ summary: recordingDataToSave.summary // <-- ADDED: Include summary+ };const response = await fetch('/save', {method: 'POST',headers: { 'Content-Type': 'application/json' },@@ -1031,65 +1355,108 @@ gunicorn==21.2.0if (!response.ok) throw new Error(data.error || 'Failed to save metadata');console.log('Save successful:', data.recording.id);+ // Update the master recordings listconst index = recordings.value.findIndex(r => r.id === data.recording.id);if (index !== -1) {- // Preserve existing transcription/status, only update metadata fields- recordings.value[index] = { ...recordings.value[index], ...payload };- }- if (selectedRecording.value?.id === data.recording.id) {- selectedRecording.value = { ...selectedRecording.value, ...payload };+ // Update only the editable fields, preserve others like status/transcription from backend+ recordings.value[index].title = payload.title;+ recordings.value[index].participants = payload.participants;+ recordings.value[index].notes = payload.notes;+ recordings.value[index].summary = payload.summary;}- if (currentRecording.value?.id === data.recording.id) {- currentRecording.value = { ...currentRecording.value, ...payload };+ // Update selected if it's the one being saved+ if (selectedRecording.value?.id === data.recording.id) {+ selectedRecording.value.title = payload.title;+ selectedRecording.value.participants = payload.participants;+ selectedRecording.value.notes = payload.notes;+ selectedRecording.value.summary = payload.summary;}- return data.recording; // Return raw response data if needed elsewhere+ return data.recording; // Return the full updated object from backend} catch (error) {console.error('Save Metadata Error:', error);setGlobalError(`Save failed: ${error.message}`);return null;}- };-+ };const loadRecordings = async () => {- globalError.value = null;+ globalError.value = null;isLoadingRecordings.value = true;try {const response = await fetch('/recordings');const data = await response.json();if (!response.ok) throw new Error(data.error || 'Failed to load recordings');-recordings.value = data;- // Check for any recordings stuck in processing state on load- recordings.value.forEach(r => {- // Resume polling only if no other polling is active- if ((r.status === 'PENDING' || r.status === 'PROCESSING') && !pollInterval.value && !isProcessing.value) {- console.log(`Resuming poll for recording ${r.id} found in state ${r.status}`);- isProcessing.value = true; // Set global processing flag to show some indicator if needed- processingStatus.message = `Resuming check for ${r.title}...`;- pollProcessingStatus(r.id);- // Note: This only resumes one at a time. A more complex system- // would track multiple background tasks.- }- });+ // On load, check for any recordings stuck in PENDING, PROCESSING, or SUMMARIZING+ // and ensure polling is active if the queue processor isn't running.+ const incompleteRecordings = recordings.value.filter(r => ['PENDING', 'PROCESSING', 'SUMMARIZING'].includes(r.status));++ if (incompleteRecordings.length > 0 && !isProcessingActive.value) {+ console.warn(`Found ${incompleteRecordings.length} incomplete recording(s) on load. Attempting to resume polling if not already queued.`);+ for (const recording of incompleteRecordings) {+ // Is this item already being tracked in the queue?+ let queueItem = uploadQueue.value.find(item => item.recordingId === recording.id);+ if (!queueItem) {+ // If not in queue (likely page reload), create a placeholder to track polling+ console.log(`Re-attaching poll for recording ${recording.id}.`);+ queueItem = {+ // Mock file object, size might be useful for display+ file: { name: recording.title || `Recording ${recording.id}`, size: recording.file_size },+ status: recording.status, // Use current status from DB+ recordingId: recording.id,+ clientId: `reload-${recording.id}`, // Unique ID for tracking+ error: null+ };+ // Add to the *beginning* of the visual queue *if* we want to show it there+ // Or just manage polling without adding to queue visually?+ // Let's add it to the queue for consistency in management.+ uploadQueue.value.unshift(queueItem);+ // Start processing queue if it wasn't active+ if (!isProcessingActive.value) {+ startProcessingQueue();+ } else if (currentlyProcessingFile.value?.recordingId !== recording.id) {+ // If processor is active but on a different file, just ensure polling starts+ // Note: startProcessingQueue handles finding the next 'queued'. This item+ // might not be 'queued'. We need direct polling.+ // Let's rethink: The queue processor should handle finding PENDING/PROCESSING items.+ // For simplicity, let's just trigger the queue processor. It will find this item if it's next.+ // If something else is truly processing, this won't interrupt.+ console.log("Triggering queue processor check due to reloaded incomplete item.")+ // Ensure it's marked conceptually 'queued' for the processor to pick up+ queueItem.status = 'queued';+ startProcessingQueue(); // Let the queue logic handle it+ }++ } else if (queueItem.status !== recording.status && !['completed', 'failed'].includes(queueItem.status)) {+ // If queue status differs from DB, update queue status+ console.log(`Correcting queue status for ${queueItem.clientId} from ${queueItem.status} to ${recording.status}`);+ queueItem.status = recording.status;+ // Restart queue processing if needed+ if (!isProcessingActive.value) startProcessingQueue();+ }+ }+ }} catch (error) {console.error('Load Recordings Error:', error);setGlobalError(`Failed to load recordings: ${error.message}`);recordings.value = [];} finally {- isLoadingRecordings.value = false;+ isLoadingRecordings.value = false;}};- const selectRecording = (recording) => {+ const selectRecording = (recording) => {selectedRecording.value = recording;- // Check status and potentially start polling if needed (handled by loadRecordings now)- };+ // Optional: Check if polling needs to be restarted if user selects an incomplete item+ // This logic is complex and might be redundant with the loadRecordings check.+ // Let's rely on loadRecordings and the queue processor for robustness.+ };const editRecording = (recording) => {- editingRecording.value = JSON.parse(JSON.stringify(recording)); // Deep copy+ // Create a deep copy for the modal to prevent modifying original object directly+ editingRecording.value = JSON.parse(JSON.stringify(recording));showEditModal.value = true;};@@ -1098,78 +1465,99 @@ gunicorn==21.2.0editingRecording.value = null;};- const saveEdit = async () => {- const updatedRecordingData = await saveMetadata(editingRecording.value);- if (updatedRecordingData) {- cancelEdit(); // Close modal on success+ const saveEdit = async () => {+ // Save using the saveMetadata function which updates the main list & selected item+ const success = await saveMetadata(editingRecording.value);+ if (success) {+ cancelEdit(); // Close modal on success}// Keep modal open on failure, error shown via globalError- };+ };const confirmDelete = (recording) => {recordingToDelete.value = recording;showDeleteModal.value = true;};- const cancelDelete = () => {+ const cancelDelete = () => {showDeleteModal.value = false;recordingToDelete.value = null;- };+ };const deleteRecording = async () => {- // ...(keep existing deleteRecording logic)...- globalError.value = null;+ globalError.value = null;if (!recordingToDelete.value) return;const idToDelete = recordingToDelete.value.id;+ const titleToDelete = recordingToDelete.value.title; // For logging/messagingtry {const response = await fetch(`/recording/${idToDelete}`, { method: 'DELETE' });const data = await response.json();if (!response.ok) throw new Error(data.error || 'Failed to delete recording');+ // Remove from gallery listrecordings.value = recordings.value.filter(r => r.id !== idToDelete);++ // Find and remove from upload queue+ const queueIndex = uploadQueue.value.findIndex(item => item.recordingId === idToDelete);+ if (queueIndex !== -1) {+ const deletedItem = uploadQueue.value.splice(queueIndex, 1)[0];+ console.log(`Removed item ${deletedItem.clientId} from queue.`);+ // If deleting the file currently being processed, stop polling and move to next+ if (currentlyProcessingFile.value?.clientId === deletedItem.clientId) {+ console.log(`Deleting currently processing file: ${titleToDelete}. Stopping poll and moving to next.`);+ clearInterval(pollInterval.value); // Stop polling explicitly+ pollInterval.value = null;+ resetCurrentFileProcessingState();+ isProcessingActive.value = false; // Allow queue to restart+ await nextTick();+ startProcessingQueue();+ }+ }+if (selectedRecording.value?.id === idToDelete) selectedRecording.value = null;cancelDelete();+ console.log(`Successfully deleted recording ${idToDelete} (${titleToDelete})`);+} catch (error) {console.error('Delete Error:', error);- setGlobalError(`Failed to delete recording: ${error.message}`);+ setGlobalError(`Failed to delete recording "${titleToDelete}": ${error.message}`);cancelDelete(); // Still close modal on error}- };+ };// --- Lifecycle Hooks ---onMounted(() => {loadRecordings();- // Set max file size from backend config if available? For now, hardcoded.- // fetch('/config').then(res => res.json()).then(cfg => maxFileSizeMB.value = cfg.max_size_mb);});// --- Watchers ---- watch(currentView, (newView) => {- // Clear selection when leaving gallery? Maybe not necessary.- // Clear errors when changing view?- // globalError.value = null;-- // If navigating away while processing an upload, keep polling but hide main spinner- if (newView !== 'upload' && isProcessing.value) {- // Allow polling to continue, but the main view spinner won't be visible+ watch(uploadQueue, (newQueue, oldQueue) => {+ if (newQueue.length === 0 && oldQueue.length > 0 && !isProcessingActive.value) {+ console.log("Upload queue processing finished.");+ // Optional: Auto-minimize after delay+ // setTimeout(() => progressPopupMinimized.value = true, 3000);}- });+ }, { deep: true });+return {// State- currentView, dragover, currentRecording, recordings, selectedRecording,+ currentView, dragover, recordings, selectedRecording, // currentRecording removedshowEditModal, showDeleteModal, editingRecording, recordingToDelete,- isProcessing, isLoadingRecordings, processingStatus, globalError, maxFileSizeMB,+ isLoadingRecordings, globalError, maxFileSizeMB,+ // Multi-upload State+ uploadQueue, currentlyProcessingFile, processingProgress, processingMessage,+ isProcessingActive, progressPopupMinimized,// Computed- groupedRecordings,+ groupedRecordings, totalInQueue, completedInQueue, queuedFiles, finishedFilesInQueue,// Methods- handleDrop, handleFileSelect, uploadFile, autoSave, loadRecordings,+ handleDrop, handleFileSelect, /*autoSave removed*/ loadRecordings,selectRecording, editRecording, cancelEdit, saveEdit, confirmDelete,cancelDelete, deleteRecording, switchToUploadView, switchToGalleryView,- formatFileSize, setGlobalError- }+ formatFileSize, setGlobalError, handleDragLeave, formatStatus, getStatusClass,+ }},- delimiters: ['${', '}']+ delimiters: ['${', '}'] // Keep Vue delimiters distinct from Flask's Jinja}).mount('#app');</script>@@ -1222,6 +1610,7 @@ After=network.target[Service]User=$USER+EnvironmentFile=/opt/transcription-app/.envWorkingDirectory=/opt/transcription-appEnvironment="PATH=/opt/transcription-app/venv/bin"Environment="PYTHONPATH=/opt/transcription-app"diff --git a/requirements.txt b/requirements.txtindex 44947cd8..dfa72596 100644--- a/requirements.txt+++ b/requirements.txt@@ -2,4 +2,5 @@ flask==2.3.3flask-sqlalchemy==3.1.1openai==1.3.0werkzeug==2.3.7-gunicorn==21.2.0\ No newline at end of file+gunicorn==21.2.0+python-dotenv==1.0.0\ No newline at end of filediff --git a/reset_db.py b/reset_db.pyindex 1d944baf..65ce8a2e 100644--- a/reset_db.py+++ b/reset_db.py@@ -4,55 +4,98 @@import osimport sys# Add project root to path if necessary for 'app' import-# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) # Adjust path as needed+# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))++# Load environment variables in case DB path relies on them (optional here)+# from dotenv import load_dotenv+# load_dotenv()# Check if running within app context already (e.g., via Flask command)try:from flask import current_app+ # Ensure app context is pushed if needed for config accessapp = current_app._get_current_object()- db = app.extensions['sqlalchemy'].db # Access db via extensions typical pattern-except RuntimeError:- # If not in app context, import directly (assuming reset_db.py is at the same level as app.py)- # This might be needed if running `python reset_db.py` directly+ # Make sure db is initialized within the app context if needed+ # (SQLAlchemy initialization in app.py handles this mostly)+ with app.app_context():+ db = app.extensions['sqlalchemy'].db # Access db via extensions+except (RuntimeError, AttributeError, KeyError):+ # If not in app context, import directlytry:+ # Ensure this import reflects the updated app.py with the new modelfrom app import app, db- except ImportError:- print("Error: Could not import 'app' and 'db'. Ensure reset_db.py is runnable.")- print("Make sure your PYTHONPATH includes the project directory or run using 'flask run <command>'")+ except ImportError as e:+ print(f"Error: Could not import 'app' and 'db': {e}")+ print("Make sure reset_db.py is runnable and PYTHONPATH is set.")sys.exit(1)-def reset_database():# Determine the database path relative to the instance folder- # Assuming app is configured with instance_relative_config=True (default)- # or manually construct path if instance folder is known+ # Use app config if availableinstance_path = app.instance_path if hasattr(app, 'instance_path') else os.path.join(os.getcwd(), 'instance')- db_filename = app.config.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///instance/transcriptions.db').split('/')[-1]- db_path = os.path.join(instance_path, db_filename)+ try:+ # Ensure app context for config access if not already present+ with app.app_context():+ # Use absolute path from config+ db_uri = app.config.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///instance/transcriptions.db')+ # Handle relative vs absolute paths specified in URI+ if db_uri.startswith('sqlite:///'):+ # Assume absolute path from URI root if starts with '///'+ db_path = db_uri.replace('sqlite:///', '/', 1) # Replace only first+ # Ensure instance path reflects the directory containing the DB+ instance_path = os.path.dirname(db_path)+ elif db_uri.startswith('sqlite://'):+ # Assume relative path from instance folder+ db_filename = db_uri.split('/')[-1]+ db_path = os.path.join(instance_path, db_filename)+ else: # Handle other DB types or formats if needed+ print(f"Warning: Non-SQLite URI detected: {db_uri}. Deletion logic might need adjustment.")+ # Attempt to parse or fallback+ db_filename = db_uri.split('/')[-1] # Best guess+ db_path = os.path.join(instance_path, db_filename)++ except Exception as config_e:+ print(f"Error accessing app config for DB path: {config_e}. Using default.")+ # Fallback if config access fails+ instance_path = os.path.join(os.getcwd(), 'instance')+ db_filename = 'transcriptions.db'+ db_path = os.path.join(instance_path, db_filename)# Ensure instance directory exists+ print(f"Ensuring instance directory exists: {instance_path}")os.makedirs(instance_path, exist_ok=True)+ print(f"Database path identified as: {db_path}")# Remove existing database if it existsif os.path.exists(db_path):print(f"Removing existing database at {db_path}")try:os.remove(db_path)+ # Also remove journal file if it exists+ journal_path = db_path + "-journal"+ if os.path.exists(journal_path):+ os.remove(journal_path)+ print(f"Removing existing journal file at {journal_path}")except OSError as e:print(f"Error removing database file: {e}. Check permissions or if it's in use.")- # Optionally exit or continue to create tables anyway+ # Decide whether to exit or continue# sys.exit(1)# Create application context to work with the database- with app.app_context():- print("Creating new database schema...")- # Create all tables defined in models- try:+ try:+ with app.app_context():+ print("Creating new database schema (including 'summary' column)...")+ # Create all tables defined in models (app.py)db.create_all()print("Database schema created successfully!")- except Exception as e:- print(f"Error creating database schema: {e}")- sys.exit(1)+ except Exception as e:+ print(f"Error creating database schema: {e}")+ # Attempt rollback if possible (though less relevant for create_all)+ try:+ db.session.rollback()+ except Exception as rb_e:+ print(f"Rollback attempt failed: {rb_e}")+ sys.exit(1)if __name__ == "__main__":print("Attempting to reset the database...")diff --git a/templates/index.html b/templates/index.htmlindex 1f852ae7..839aad42 100644--- a/templates/index.html+++ b/templates/index.html@@ -8,71 +8,59 @@<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"><style>- /* Add a subtle transition for dragover effect */- .drag-area {- transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;+ /* Existing styles... */+ .drag-area { transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out; }+ .custom-scrollbar::-webkit-scrollbar { width: 8px; }+ .custom-scrollbar::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }+ .custom-scrollbar::-webkit-scrollbar-thumb { background: #c5c5c5; border-radius: 10px; }+ .custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }+ html, body { height: 100%; margin: 0; }+ #app { min-height: 100%; display: flex; flex-direction: column; }+ main { flex-grow: 1; position: relative; }+ .progress-popup { position: fixed; bottom: 1rem; left: 1rem; z-index: 100; transition: all 0.3s ease-in-out; min-width: 300px; }+ .progress-popup.minimized { transform: translateY(calc(100% - 45px)); }+ .progress-list-item { display: grid; grid-template-columns: auto 1fr auto; gap: 0.5rem; align-items: center; }+ /* Add style for summary pre */+ .summary-box {+ background-color: #f9fafb; /* bg-gray-50 */+ padding: 0.75rem; /* p-3 */+ border-radius: 0.375rem; /* rounded */+ border: 1px solid #e5e7eb; /* border-gray-200 */+ min-height: 60px; /* min-h-[60px] or adjust as needed */+ max-height: 20rem; /* Limit height */+ overflow-y: auto;+ white-space: pre-wrap;+ font-family: inherit; /* Use body font */+ font-size: 0.875rem; /* text-sm */+ line-height: 1.25rem;}- /* Custom scrollbar for webkit browsers (optional) */- .custom-scrollbar::-webkit-scrollbar {- width: 8px;- }- .custom-scrollbar::-webkit-scrollbar-track {- background: #f1f1f1;- border-radius: 10px;- }- .custom-scrollbar::-webkit-scrollbar-thumb {- background: #c5c5c5;- border-radius: 10px;- }- .custom-scrollbar::-webkit-scrollbar-thumb:hover {- background: #a8a8a8;- }- /* Ensure body takes full height for drop zone */- html, body {- height: 100%;- margin: 0;- }- #app {- min-height: 100%;- display: flex;- flex-direction: column;- }- main {- flex-grow: 1;- position: relative; /* Needed for absolute positioning of drag overlay */- }- /* Progress Popup Styles */- .progress-popup {- position: fixed;- bottom: 1rem;- left: 1rem;- z-index: 100; /* Ensure it's above other elements */- transition: all 0.3s ease-in-out;- min-width: 300px; /* Minimum width */- }- .progress-popup.minimized {- transform: translateY(calc(100% - 45px)); /* Adjust based on header height */- }- .progress-list-item {- display: grid;- grid-template-columns: auto 1fr auto;- gap: 0.5rem;- align-items: center;+ .status-badge {+ display: inline-block;+ padding: 0.125rem 0.5rem; /* px-2 py-0.5 */+ font-size: 0.75rem; /* text-xs */+ font-weight: 600; /* font-semibold */+ border-radius: 9999px; /* rounded-full */+ margin-top: 0.5rem; /* mt-2 */}+ .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 */+ .status-completed { color: #065f46; background-color: #d1fae5; } /* text-green-800 bg-green-100 */+ .status-failed { color: #991b1b; background-color: #fee2e2; } /* text-red-800 bg-red-100 */+ .status-pending { color: #57534e; background-color: #f5f5f4; } /* text-stone-700 bg-stone-100 */</style></head><body class="bg-gray-100"><div id="app" class="container mx-auto px-4 sm:px-6 lg:px-8 py-6 flex flex-col"><header class="flex justify-between items-center mb-6 pb-4 border-b border-gray-200">- <h1 class="text-3xl font-bold text-gray-800 cursor-pointer" @click="switchToGalleryView" title="Go to Gallery">- Audio Transcription+ <h1 class="text-3xl font-bold text-gray-800 cursor-pointer" @click="switchToGalleryView" title="Go to Gallery">+ Audio Transcription & Summary</h1><div><button @click="switchToUploadView" class="px-4 py-2 mr-2 bg-blue-600 text-white rounded-lg shadow hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition duration-150 ease-in-out"><i class="fas fa-plus mr-1"></i> New Recording</button>- <button+ <button@click="switchToGalleryView":class="{'bg-white text-gray-700 border border-gray-300': currentView !== 'gallery',@@ -85,7 +73,7 @@</header><div v-if="globalError" class="mb-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg" role="alert">- <div class="flex justify-between items-center">+ <div class="flex justify-between items-center"><div><strong class="font-bold">Error:</strong><span class="block sm:inline ml-2">${ globalError }</span>@@ -95,123 +83,151 @@</div><main class="flex-grow"- @dragover.prevent="dragover = true"- @dragleave.prevent="handleDragLeave"- @drop.prevent="handleDrop">-- <div v-if="dragover" class="absolute inset-0 flex items-center justify-center bg-blue-500 bg-opacity-20 z-10 rounded-lg pointer-events-none border-4 border-dashed border-blue-600">- <div class="text-center p-6 bg-white rounded-lg shadow-xl">- <i class="fas fa-upload text-4xl text-blue-500 mb-3"></i>- <p class="text-xl font-semibold text-gray-700">Drop audio file(s) here to upload</p>- </div>- </div>+ @dragover.prevent="dragover = true"+ @dragleave.prevent="handleDragLeave"+ @drop.prevent="handleDrop">++ <div v-if="dragover" class="absolute inset-0 flex items-center justify-center bg-blue-500 bg-opacity-20 z-10 rounded-lg pointer-events-none border-4 border-dashed border-blue-600">+ <div class="text-center p-6 bg-white rounded-lg shadow-xl">+ <i class="fas fa-upload text-4xl text-blue-500 mb-3"></i>+ <p class="text-xl font-semibold text-gray-700">Drop audio file(s) here to upload</p>+ </div>+ </div><div v-if="currentView === 'gallery'" class="flex-grow flex flex-col rounded-lg">- <div class="grid grid-cols-1 lg:grid-cols-4 gap-6 flex-grow">+ <div class="grid grid-cols-1 lg:grid-cols-4 gap-6 flex-grow"><div class="lg:col-span-1 bg-white p-4 rounded-lg shadow-md flex flex-col"><h3 class="text-lg font-semibold mb-4 sticky top-0 bg-white pb-3 border-b border-gray-200">Recordings</h3>- <div v-if="isLoadingRecordings" class="text-center text-gray-500 py-4">+ <div v-if="isLoadingRecordings" class="text-center text-gray-500 py-4"><i class="fas fa-spinner fa-spin mr-2"></i> Loading recordings...</div>- <div v-else-if="recordings.length === 0 && uploadQueue.length === 0" class="text-center text-gray-500 py-4 flex-grow flex flex-col items-center justify-center">- <i class="fas fa-folder-open text-4xl text-gray-400 mb-3"></i>+ <div v-else-if="recordings.length === 0 && uploadQueue.length === 0" class="text-center text-gray-500 py-4 flex-grow flex flex-col items-center justify-center">+ <i class="fas fa-folder-open text-4xl text-gray-400 mb-3"></i><p>No recordings yet.</p><p>Upload one or drag & drop anywhere!</p></div><div v-else class="space-y-4 overflow-y-auto custom-scrollbar flex-grow pr-1">- <div v-for="group in groupedRecordings" :key="group.title" class="mb-3">- <h4 class="font-medium text-gray-500 text-xs uppercase tracking-wider mb-2 sticky top-0 bg-white py-1">${ group.title }</h4>- <ul class="space-y-1">- <li v-for="recording in group.items"- :key="recording.id"- @click="selectRecording(recording)"- class="cursor-pointer p-3 rounded-md flex justify-between items-center transition duration-150 ease-in-out"- :class="{- 'bg-blue-100 hover:bg-blue-200 ring-1 ring-blue-300': selectedRecording?.id === recording.id,- 'hover:bg-gray-100': selectedRecording?.id !== recording.id- }">+ <div v-for="group in groupedRecordings" :key="group.title" class="mb-3">+ <h4 class="font-medium text-gray-500 text-xs uppercase tracking-wider mb-2 sticky top-0 bg-white py-1">${ group.title }</h4>+ <ul class="space-y-1">+ <li v-for="recording in group.items"+ :key="recording.id"+ @click="selectRecording(recording)"+ class="cursor-pointer p-3 rounded-md flex justify-between items-center transition duration-150 ease-in-out"+ :class="{+ 'bg-blue-100 hover:bg-blue-200 ring-1 ring-blue-300': selectedRecording?.id === recording.id,+ 'hover:bg-gray-100': selectedRecording?.id !== recording.id+ }"><div class="flex items-center overflow-hidden mr-2">- <i class="fas fa-file-audio text-blue-500 mr-2 flex-shrink-0"></i>- <span class="text-sm font-medium text-gray-800 truncate">${ recording.title }</span>- </div>- <div class="flex space-x-2 flex-shrink-0 items-center">- <span v-if="recording.status === 'PROCESSING' || recording.status === 'PENDING'" class="text-xs text-blue-600 italic flex items-center" title="Processing...">- <i class="fas fa-spinner fa-spin mr-1"></i> Processing- </span>- <span v-else-if="recording.status === 'FAILED'" class="text-xs text-red-600 italic flex items-center" title="Transcription Failed">- <i class="fas fa-exclamation-triangle mr-1"></i> Failed- </span>- <span v-else-if="recording.status === 'COMPLETED'" class="text-xs text-green-600" title="Completed">- <i class="fas fa-check-circle"></i>- </span>+ <i class="fas fa-file-audio text-blue-500 mr-2 flex-shrink-0"></i>+ <span class="text-sm font-medium text-gray-800 truncate" :title="recording.title || 'Loading title...'">${ recording.title || '(Processing...)' }</span>+ </div>+ <div class="flex space-x-2 flex-shrink-0 items-center">+ <span v-if="recording.status === 'PROCESSING'" class="text-xs text-blue-600 italic flex items-center" title="Transcribing...">+ <i class="fas fa-spinner fa-spin mr-1"></i> Transcribing+ </span>+ <span v-else-if="recording.status === 'SUMMARIZING'" class="text-xs text-amber-600 italic flex items-center" title="Generating Summary...">+ <i class="fas fa-spinner fa-spin mr-1"></i> Summarizing+ </span>+ <span v-else-if="recording.status === 'PENDING'" class="text-xs text-gray-500 italic flex items-center" title="Waiting...">+ <i class="fas fa-clock mr-1"></i> Pending+ </span>+ <span v-else-if="recording.status === 'FAILED'" class="text-xs text-red-600 italic flex items-center" title="Processing Failed">+ <i class="fas fa-exclamation-triangle mr-1"></i> Failed+ </span>+ <span v-else-if="recording.status === 'COMPLETED'" class="text-xs text-green-600" title="Completed">+ <i class="fas fa-check-circle"></i>+ </span><button @click.stop="editRecording(recording)" class="text-gray-500 hover:text-blue-600 text-xs p-1 rounded hover:bg-gray-200" title="Edit Details">- <i class="fas fa-edit"></i>- </button>- <button @click.stop="confirmDelete(recording)" class="text-gray-500 hover:text-red-600 text-xs p-1 rounded hover:bg-gray-200" title="Delete Recording">- <i class="fas fa-trash"></i>- </button>- </div>- </li>- </ul>- </div>- </div>+ <i class="fas fa-edit"></i>+ </button>+ <button @click.stop="confirmDelete(recording)" class="text-gray-500 hover:text-red-600 text-xs p-1 rounded hover:bg-gray-200" title="Delete Recording">+ <i class="fas fa-trash"></i>+ </button>+ </div>+ </li>+ </ul>+ </div>+ </div></div>- <div class="lg:col-span-3 bg-white p-6 rounded-lg shadow-md flex flex-col">- <div v-if="selectedRecording" class="flex-grow">- <div class="flex flex-col sm:flex-row justify-between items-start mb-4 border-b border-gray-200 pb-4">- <div class="mb-3 sm:mb-0">- <h3 class="text-2xl font-semibold text-gray-900">${ selectedRecording.title }</h3>- <p class="text-sm text-gray-500 mt-1">- Created: ${ new Date(selectedRecording.created_at).toLocaleString() } | Size: ${ formatFileSize(selectedRecording.file_size) }- </p>- <span v-if="selectedRecording.status === 'PROCESSING' || selectedRecording.status === 'PENDING'" class="mt-2 inline-block px-2 py-0.5 text-xs font-semibold text-blue-800 bg-blue-100 rounded-full">Status: Processing</span>- <span v-else-if="selectedRecording.status === 'FAILED'" class="mt-2 inline-block px-2 py-0.5 text-xs font-semibold text-red-800 bg-red-100 rounded-full">Status: Failed</span>- <span v-else-if="selectedRecording.status === 'COMPLETED'" class="mt-2 inline-block px-2 py-0.5 text-xs font-semibold text-green-800 bg-green-100 rounded-full">Status: Completed</span>- </div>- <div class="flex space-x-2 flex-shrink-0">- <button @click="editRecording(selectedRecording)" class="px-3 py-1.5 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm shadow-sm">- <i class="fas fa-edit mr-1"></i> Edit Details- </button>- <button @click="confirmDelete(selectedRecording)" class="px-3 py-1.5 bg-red-600 text-white rounded-md hover:bg-red-700 text-sm shadow-sm">- <i class="fas fa-trash mr-1"></i> Delete- </button>- </div>- </div>- <div class="grid md:grid-cols-2 gap-6">- <div>- <h4 class="font-semibold text-gray-700 mb-2">Transcription</h4>- <div v-if="selectedRecording.status === 'COMPLETED'" class="h-96 overflow-y-auto p-4 bg-gray-50 rounded border border-gray-200 text-sm custom-scrollbar">- <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'No transcription available.' }</pre>- </div>- <div v-else-if="selectedRecording.status === 'FAILED'" class="h-96 overflow-y-auto p-4 bg-red-50 rounded border border-red-200 text-sm text-red-700 custom-scrollbar">- <p class="font-medium mb-2">Transcription Failed:</p>- <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'An unknown error occurred.' }</pre>- </div>- <div v-else class="h-96 flex items-center justify-center p-4 bg-gray-50 rounded border border-gray-200 text-gray-500">- <i class="fas fa-spinner fa-spin mr-2"></i> Transcription in progress...- </div>- </div>- <div class="space-y-4">- <div>- <h4 class="font-semibold text-gray-700 mb-2">Audio Player</h4>- <audio controls class="w-full" :key="selectedRecording.id" :src="'/audio/' + selectedRecording.id">- Your browser does not support the audio element.- </audio>- </div>- <div>- <h4 class="font-semibold text-gray-700 mb-1">Participants</h4>- <p class="text-sm bg-gray-50 p-3 rounded border border-gray-200 min-h-[40px]">${ selectedRecording.participants || 'None specified' }</p>- </div>- <div>- <h4 class="font-semibold text-gray-700 mb-1">Notes</h4>- <pre class="text-sm bg-gray-50 p-3 rounded border border-gray-200 whitespace-pre-wrap h-40 overflow-y-auto custom-scrollbar font-sans">${ selectedRecording.notes || 'No notes' }</pre>- </div>- </div>- </div>- </div>- <div v-else class="flex flex-col items-center justify-center text-center text-gray-500 flex-grow">- <i class="fas fa-hand-pointer text-4xl text-gray-400 mb-4"></i>+ <div class="lg:col-span-3 bg-white p-6 rounded-lg shadow-md flex flex-col">+ <div v-if="selectedRecording" class="flex-grow flex flex-col">+ <div class="flex flex-col sm:flex-row justify-between items-start mb-4 border-b border-gray-200 pb-4">+ <div class="mb-3 sm:mb-0 max-w-lg">+ <h3 class="text-2xl font-semibold text-gray-900">${ selectedRecording.title || 'Loading...' }</h3>+ <p class="text-sm text-gray-500 mt-1">+ Created: ${ new Date(selectedRecording.created_at).toLocaleString() } | Size: ${ formatFileSize(selectedRecording.file_size) }+ </p>+ <span :class="getStatusClass(selectedRecording.status)" class="status-badge">+ Status: ${ formatStatus(selectedRecording.status) }+ </span>+ </div>+ <div class="flex space-x-2 flex-shrink-0">+ <button @click="editRecording(selectedRecording)" class="px-3 py-1.5 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm shadow-sm">+ <i class="fas fa-edit mr-1"></i> Edit Details+ </button>+ <button @click="confirmDelete(selectedRecording)" class="px-3 py-1.5 bg-red-600 text-white rounded-md hover:bg-red-700 text-sm shadow-sm">+ <i class="fas fa-trash mr-1"></i> Delete+ </button>+ </div>+ </div>++ <div class="grid md:grid-cols-2 gap-6 flex-grow overflow-hidden">+ <div class="flex flex-col overflow-hidden">+ <h4 class="font-semibold text-gray-700 mb-2 flex-shrink-0">Transcription</h4>+ <div class="flex-grow overflow-y-auto p-4 bg-gray-50 rounded border border-gray-200 text-sm custom-scrollbar">+ <div v-if="selectedRecording.status === 'COMPLETED' || selectedRecording.status === 'SUMMARIZING'">+ <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'No transcription available.' }</pre>+ </div>+ <div v-else-if="selectedRecording.status === 'FAILED'" class="text-red-700">+ <p class="font-medium mb-2">Processing Failed:</p>+ <pre class="whitespace-pre-wrap font-sans">${ selectedRecording.transcription || 'An unknown error occurred.' }</pre>+ </div>+ <div v-else class="flex items-center justify-center text-gray-500 h-full">+ <i class="fas fa-spinner fa-spin mr-2"></i> Transcription in progress...+ </div>+ </div>+ </div>++ <div class="flex flex-col space-y-4 overflow-hidden">+ <div>+ <h4 class="font-semibold text-gray-700 mb-2">Audio Player</h4>+ <audio controls class="w-full" :key="selectedRecording.id" :src="'/audio/' + selectedRecording.id">+ Your browser does not support the audio element.+ </audio>+ </div>++ <div class="flex flex-col overflow-hidden">+ <h4 class="font-semibold text-gray-700 mb-2 flex-shrink-0">Summary</h4>+ <div class="flex-grow overflow-hidden">+ <div v-if="selectedRecording.status === 'COMPLETED'" class="summary-box custom-scrollbar">+ ${ selectedRecording.summary || 'No summary generated.' }+ </div>+ <div v-else-if="selectedRecording.status === 'FAILED'" class="summary-box text-red-700 custom-scrollbar">+ ${ selectedRecording.summary || 'Summary generation failed or was skipped.' }+ </div>+ <div v-else class="h-24 flex items-center justify-center p-4 bg-gray-50 rounded border border-gray-200 text-gray-500">+ <i class="fas fa-spinner fa-spin mr-2"></i> Summary pending...+ </div>+ </div>+ </div>++ <div>+ <h4 class="font-semibold text-gray-700 mb-1">Participants</h4>+ <p class="text-sm bg-gray-50 p-3 rounded border border-gray-200 min-h-[40px]">${ selectedRecording.participants || 'None specified' }</p>+ </div>+ <div class="flex flex-col overflow-hidden flex-grow">+ <h4 class="font-semibold text-gray-700 mb-1 flex-shrink-0">Notes</h4>+ <div class="flex-grow overflow-hidden">+ <pre class="text-sm bg-gray-50 p-3 rounded border border-gray-200 whitespace-pre-wrap h-40 overflow-y-auto custom-scrollbar font-sans">${ selectedRecording.notes || 'No notes' }</pre>+ </div>+ </div>+ </div>+ </div>+ </div>+ <div v-else class="flex flex-col items-center justify-center text-center text-gray-500 flex-grow">+ <i class="fas fa-hand-pointer text-4xl text-gray-400 mb-4"></i><p class="text-lg font-medium mb-2">Select a recording from the list to view details.</p><p>Or, drag and drop audio file(s) anywhere on this page to upload.</p></div>@@ -219,229 +235,183 @@</div></div>- <div v-if="currentView === 'upload'"+ <div v-if="currentView === 'upload'"class="flex-grow flex items-center justify-center p-4"><div class="w-full max-w-lg bg-white p-8 rounded-xl shadow-lg border border-gray-200 text-center drag-area":class="{'border-blue-500 bg-blue-50': dragover}">- <div class="py-8">- <i class="fas fa-cloud-upload-alt text-5xl mb-5 text-blue-500"></i>+ <div class="py-8">+ <i class="fas fa-cloud-upload-alt text-5xl mb-5 text-blue-500"></i><h2 class="text-xl font-semibold text-gray-700 mb-2">Upload New Recordings</h2>- <p class="text-gray-500 mb-4">Drag & drop your audio files here or click below.</p>+ <p class="text-gray-500 mb-4">Drag & drop your audio files here or click below.</p><input type="file" @change="handleFileSelect" accept="audio/*" class="hidden" ref="fileInput" multiple>- <button @click="$refs.fileInput.click()" class="mt-4 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 shadow-sm transition duration-150 ease-in-out">- <i class="fas fa-file-import mr-2"></i> Select Files- </button>+ <button @click="$refs.fileInput.click()" class="mt-4 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 shadow-sm transition duration-150 ease-in-out">+ <i class="fas fa-file-import mr-2"></i> Select Files+ </button><p class="text-xs text-gray-400 mt-4">Max file size per file: ${ maxFileSizeMB } MB</p>- </div>- </div>- </div>-- <div v-if="currentView === 'input' && currentRecording" class="bg-white p-6 md:p-8 rounded-lg shadow-md border border-gray-200">- <div class="flex justify-between items-center mb-6 pb-4 border-b border-gray-200">- <h2 class="text-2xl font-semibold text-gray-800">Recording Details</h2>- <button @click="switchToGalleryView" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition duration-150 ease-in-out">- <i class="fas fa-arrow-left mr-2"></i> Back to Gallery- </button>- </div>- <div class="grid md:grid-cols-2 gap-8">- <div>- <h3 class="text-lg font-semibold text-gray-700 mb-3">Transcription</h3>- <div class="h-96 overflow-y-auto p-4 bg-gray-50 rounded border border-gray-200 text-sm custom-scrollbar">- <pre class="whitespace-pre-wrap font-sans">${ currentRecording.transcription || 'Transcription not available.' }</pre>- </div>- </div>- <div>- <h3 class="text-lg font-semibold text-gray-700 mb-3">Add Recording Details</h3>- <div class="space-y-4">- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Title</label>- <input v-model="currentRecording.title"- @input="autoSave"- placeholder="Enter a title for this recording"- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50">- </div>- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Participants</label>- <input v-model="currentRecording.participants"- @input="autoSave"- placeholder="e.g., John Doe, Jane Smith"- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50">- </div>- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label>- <textarea v-model="currentRecording.notes"- @input="autoSave"- placeholder="Add any relevant notes here..."- class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50"- rows="5"></textarea>- </div>- <div class="text-sm text-gray-500 pt-2">- <p>File Size: ${ formatFileSize(currentRecording.file_size) }</p>- <p>Created: ${ new Date(currentRecording.created_at).toLocaleString() }</p>- <p class="text-green-600 font-medium mt-2">Details are auto-saved.</p>- </div>- </div>- </div>- </div>- </div>+ </div>+ </div>+ </div>- </main>+ </main><footer class="text-center py-4 mt-8 text-xs text-gray-400 border-t border-gray-200">Audio Transcription App © ${ new Date().getFullYear() }</footer>- <div v-if="showEditModal" class="fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4">- <div class="bg-white p-6 rounded-lg shadow-xl w-full max-w-lg max-h-[90vh] overflow-y-auto">- <div class="flex justify-between items-center mb-4">- <h3 class="text-xl font-semibold text-gray-800">Edit Recording Details</h3>- <button @click="cancelEdit" class="text-gray-400 hover:text-gray-600 text-2xl leading-none">×</button>- </div>- <div v-if="editingRecording" class="space-y-4">- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Title</label>- <input v-model="editingRecording.title" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50">- </div>- <div>- <label class="block text-sm font-medium text-gray-700 mb-1">Participants</label>- <input v-model="editingRecording.participants" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50">- </div>+ <div v-if="showEditModal" class="fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4">+ <div class="bg-white p-6 rounded-lg shadow-xl w-full max-w-lg max-h-[90vh] overflow-y-auto custom-scrollbar">+ <div class="flex justify-between items-center mb-4">+ <h3 class="text-xl font-semibold text-gray-800">Edit Recording Details</h3>+ <button @click="cancelEdit" class="text-gray-400 hover:text-gray-600 text-2xl leading-none">×</button>+ </div>+ <div v-if="editingRecording" class="space-y-4">+ <div>+ <label class="block text-sm font-medium text-gray-700 mb-1">Title</label>+ <input v-model="editingRecording.title" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50">+ </div>+ <div>+ <label class="block text-sm font-medium text-gray-700 mb-1">Participants</label>+ <input v-model="editingRecording.participants" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50">+ </div><div>- <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label>- <textarea v-model="editingRecording.notes" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50" rows="4"></textarea>- </div>- <div class="flex justify-end space-x-3 pt-4">- <button @click="cancelEdit" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Cancel</button>- <button @click="saveEdit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Save Changes</button>- </div>- </div>- </div>- </div>+ <label class="block text-sm font-medium text-gray-700 mb-1">Summary</label>+ <textarea v-model="editingRecording.summary" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50" rows="5"></textarea>+ </div>+ <div>+ <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label>+ <textarea v-model="editingRecording.notes" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-200 focus:ring-opacity-50" rows="4"></textarea>+ </div>+ <div class="flex justify-end space-x-3 pt-4">+ <button @click="cancelEdit" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Cancel</button>+ <button @click="saveEdit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Save Changes</button>+ </div>+ </div>+ </div>+ </div><div v-if="showDeleteModal" class="fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4"><div class="bg-white p-6 rounded-lg shadow-xl max-w-md w-full">- <h3 class="text-lg font-semibold text-gray-800 mb-4">Confirm Delete</h3>+ <h3 class="text-lg font-semibold text-gray-800 mb-4">Confirm Delete</h3><p v-if="recordingToDelete" class="mb-2 text-gray-600">Are you sure you want to permanently delete the recording titled "<strong>${ recordingToDelete.title }</strong>"?</p>- <p class="text-sm text-red-600 mb-6">This action cannot be undone and will delete both the record and the audio file.</p>- <div class="flex justify-end space-x-3">- <button @click="cancelDelete" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Cancel</button>- <button @click="deleteRecording" class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700">Delete Permanently</button>- </div>- </div>- </div>-- <div v-if="uploadQueue.length > 0 || currentlyProcessingFile"- class="progress-popup bg-white rounded-lg shadow-xl border border-gray-200 overflow-hidden"- :class="{ 'minimized': progressPopupMinimized }">-- <div class="flex justify-between items-center p-2 bg-gray-100 border-b border-gray-200 cursor-pointer" @click="progressPopupMinimized = !progressPopupMinimized">- <h4 class="text-sm font-semibold text-gray-700">- <i class="fas fa-upload mr-2 text-blue-500"></i>- Upload Progress (${ completedInQueue }/${ totalInQueue } completed)- </h4>- <button class="text-gray-500 hover:text-gray-700">- <i :class="progressPopupMinimized ? 'fa-chevron-up' : 'fa-chevron-down'" class="fas fa-fw"></i>- </button>- </div>+ <p class="text-sm text-red-600 mb-6">This action cannot be undone and will delete the record, transcription, summary, and the audio file.</p>+ <div class="flex justify-end space-x-3">+ <button @click="cancelDelete" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Cancel</button>+ <button @click="deleteRecording" class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700">Delete Permanently</button>+ </div>+ </div>+ </div>++ <div v-if="uploadQueue.length > 0 || currentlyProcessingFile"+ class="progress-popup bg-white rounded-lg shadow-xl border border-gray-200 overflow-hidden"+ :class="{ 'minimized': progressPopupMinimized }">++ <div class="flex justify-between items-center p-2 bg-gray-100 border-b border-gray-200 cursor-pointer" @click="progressPopupMinimized = !progressPopupMinimized">+ <h4 class="text-sm font-semibold text-gray-700">+ <i class="fas fa-upload mr-2 text-blue-500"></i>+ Upload & Process Progress (${ completedInQueue }/${ totalInQueue } completed)+ </h4>+ <button class="text-gray-500 hover:text-gray-700">+ <i :class="progressPopupMinimized ? 'fa-chevron-up' : 'fa-chevron-down'" class="fas fa-fw"></i>+ </button>+ </div><div class="p-3 max-h-60 overflow-y-auto custom-scrollbar" v-show="!progressPopupMinimized"><div v-if="currentlyProcessingFile" class="mb-3 pb-3 border-b border-dashed border-gray-200"><div class="flex items-center justify-between mb-1">- <p class="text-xs font-medium text-gray-800 truncate mr-2" :title="currentlyProcessingFile.file.name">- <i class="fas fa-spinner fa-spin text-blue-500 mr-1"></i> Processing: ${ currentlyProcessingFile.file.name }- </p>- <span class="text-xs text-gray-500 flex-shrink-0">${ formatFileSize(currentlyProcessingFile.file.size) }</span>+ <p class="text-xs font-medium text-gray-800 truncate mr-2" :title="currentlyProcessingFile.file.name">+ <i class="fas fa-spinner fa-spin text-blue-500 mr-1"></i> Processing: ${ currentlyProcessingFile.file.name }+ </p>+ <span class="text-xs text-gray-500 flex-shrink-0">${ formatFileSize(currentlyProcessingFile.file.size) }</span></div><p class="text-xs text-gray-600 mb-1 italic">${ processingMessage }</p>- <div class="w-full bg-gray-200 rounded-full h-1.5">+ <div class="w-full bg-gray-200 rounded-full h-1.5"><div class="bg-blue-500 h-1.5 rounded-full transition-all duration-300" :style="{ width: processingProgress + '%' }"></div>- </div>- </div>+ </div>+ </div><div v-if="queuedFiles.length > 0" class="mb-2">- <p class="text-xs font-semibold text-gray-500 mb-1">${ queuedFiles.length } file(s) queued:</p>- <ul class="space-y-1">- <li v-for="item in queuedFiles" :key="item.clientId" class="text-xs text-gray-600 progress-list-item">- <i class="fas fa-clock text-gray-400 fa-fw"></i>- <span class="truncate" :title="item.file.name">${ item.file.name }</span>- <span class="text-gray-400 flex-shrink-0">${ formatFileSize(item.file.size) }</span>- </li>- </ul>- </div>-- <div v-if="finishedFilesInQueue.length > 0" class="mt-2 pt-2 border-t border-dashed border-gray-200">- <p class="text-xs font-semibold text-gray-500 mb-1">Recently finished:</p>- <ul class="space-y-1">+ <p class="text-xs font-semibold text-gray-500 mb-1">${ queuedFiles.length } file(s) queued:</p>+ <ul class="space-y-1">+ <li v-for="item in queuedFiles" :key="item.clientId" class="text-xs text-gray-600 progress-list-item">+ <i class="fas fa-clock text-gray-400 fa-fw"></i>+ <span class="truncate" :title="item.file.name">${ item.file.name }</span>+ <span class="text-gray-400 flex-shrink-0">${ formatFileSize(item.file.size) }</span>+ </li>+ </ul>+ </div>++ <div v-if="finishedFilesInQueue.length > 0" class="mt-2 pt-2 border-t border-dashed border-gray-200">+ <p class="text-xs font-semibold text-gray-500 mb-1">Recently finished:</p>+ <ul class="space-y-1"><li v-for="item in finishedFilesInQueue.slice(-5)" :key="item.clientId" class="text-xs progress-list-item"><i v-if="item.status === 'completed'" class="fas fa-check-circle text-green-500 fa-fw"></i>- <i v-else-if="item.status === 'failed'" class="fas fa-exclamation-triangle text-red-500 fa-fw"></i>- <span class="truncate" :title="item.file.name">${ item.file.name }</span>- <span v-if="item.status === 'failed'" class="text-red-500 text-xs italic flex-shrink-0">Failed</span>- <span v-else class="text-gray-400 flex-shrink-0">${ formatFileSize(item.file.size) }</span>- </li>- </ul>- </div>-- <div v-if="uploadQueue.length > 0 && queuedFiles.length === 0 && !currentlyProcessingFile" class="text-xs text-center text-gray-500 py-2">- All uploads processed.- </div>- </div>- </div>+ <i v-else-if="item.status === 'failed'" class="fas fa-exclamation-triangle text-red-500 fa-fw"></i>+ <i v-else class="fas fa-question-circle text-gray-400 fa-fw"></i>+ <span class="truncate" :title="item.file.name">${ item.file.name }</span>+ <span v-if="item.status === 'failed'" class="text-red-500 text-xs italic flex-shrink-0">Failed</span>+ <span v-else class="text-gray-400 flex-shrink-0">${ formatFileSize(item.file.size) }</span>+ </li>+ </ul>+ </div>++ <div v-if="uploadQueue.length > 0 && queuedFiles.length === 0 && !currentlyProcessingFile" class="text-xs text-center text-gray-500 py-2">+ All uploads processed.+ </div>+ </div>+ </div></div> <script>const { createApp, ref, reactive, computed, onMounted, watch, nextTick } = VuecreateApp({setup() {- const currentView = ref('gallery'); // Default view+ const currentView = ref('gallery');const dragover = ref(false);- const recordings = ref([]); // Gallery list- const selectedRecording = ref(null); // Gallery detail view- const currentRecording = ref(null); // Input view details (less used now)-- // --- NEW State for Multi-Upload ---- const uploadQueue = ref([]); // Array of { file: File, status: 'queued'|'uploading'|'processing'|'completed'|'failed', recordingId: null|int, clientId: string, error: null|string }- const currentlyProcessingFile = ref(null); // Reference to the item in uploadQueue currently being processed- const processingProgress = ref(0); // Progress of the *current* file (0-100)- const processingMessage = ref(''); // Status message for the *current* file- const isProcessingActive = ref(false); // Is the queue processor running?+ const recordings = ref([]);+ const selectedRecording = ref(null);+ // const currentRecording = ref(null); // Less used now with modal editing++ // --- Multi-Upload State ---+ // Status: 'queued'|'uploading'|'processing'|'summarizing'|'completed'|'failed'+ const uploadQueue = ref([]);+ const currentlyProcessingFile = ref(null);+ const processingProgress = ref(0);+ const processingMessage = ref('');+ const isProcessingActive = ref(false);const pollInterval = ref(null);- const progressPopupMinimized = ref(false); // State for the popup view- // -----------------------------------+ const progressPopupMinimized = ref(false);const showEditModal = ref(false);const showDeleteModal = ref(false);- const editingRecording = ref(null);+ const editingRecording = ref(null); // Holds a *copy* for the modalconst recordingToDelete = ref(null);- const autoSaveTimeout = ref(null);+ // const autoSaveTimeout = ref(null); // Autosave not implemented for modalconst isLoadingRecordings = ref(true);const globalError = ref(null);- const maxFileSizeMB = ref(250); // Set your max file size here+ const maxFileSizeMB = ref(250); // Default, could fetch from config if needed// --- Computed Properties ---const groupedRecordings = computed(() => {- // Sort recordings newest first before groupingconst sortedRecordings = [...recordings.value].sort((a, b) => new Date(b.created_at) - new Date(a.created_at));-+ // Grouping logic (same as before)...const groups = { today: [], yesterday: [], thisWeek: [], older: [] };const now = new Date();const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());const yesterdayStart = new Date(todayStart);yesterdayStart.setDate(todayStart.getDate() - 1);- const currentDayOfWeek = now.getDay(); // 0 = Sunday- const daysToSubtract = currentDayOfWeek === 0 ? 6 : currentDayOfWeek - 1; // Assuming Monday is start+ const currentDayOfWeek = now.getDay();+ const daysToSubtract = currentDayOfWeek === 0 ? 6 : currentDayOfWeek - 1;const weekStart = new Date(todayStart);weekStart.setDate(todayStart.getDate() - daysToSubtract);sortedRecordings.forEach(r => {- const date = new Date(r.created_at);+ const date = new Date(r.created_at);if (date >= todayStart) groups.today.push(r);else if (date >= yesterdayStart) groups.yesterday.push(r);else if (date >= weekStart) groups.thisWeek.push(r);else groups.older.push(r);});-- return [+ return [{ title: 'Today', items: groups.today },{ title: 'Yesterday', items: groups.yesterday },{ title: 'This Week', items: groups.thisWeek },@@ -449,34 +419,51 @@].filter(g => g.items.length > 0);});- // Computed properties for the progress popupconst totalInQueue = computed(() => uploadQueue.value.length);- const completedInQueue = computed(() => uploadQueue.value.filter(item => item.status === 'completed' || item.status === 'failed').length);- const queuedFiles = computed(() => uploadQueue.value.filter(item => item.status === 'queued'));- const finishedFilesInQueue = computed(() => uploadQueue.value.filter(item => item.status === 'completed' || item.status === 'failed'));+ const completedInQueue = computed(() => uploadQueue.value.filter(item => item.status === 'completed' || item.status === 'failed').length);+ const queuedFiles = computed(() => uploadQueue.value.filter(item => item.status === 'queued'));+ // Filter finished: includes completed and failed+ const finishedFilesInQueue = computed(() => uploadQueue.value.filter(item => ['completed', 'failed'].includes(item.status)));// --- Methods ---const setGlobalError = (message, duration = 7000) => {- globalError.value = message;+ globalError.value = message;if (duration > 0) {- setTimeout(() => { if (globalError.value === message) globalError.value = null; }, duration);- }+ setTimeout(() => { if (globalError.value === message) globalError.value = null; }, duration);+ }};- const formatFileSize = (bytes) => {- if (bytes == null || bytes === 0) return '0 Bytes';+ const formatFileSize = (bytes) => {+ if (bytes == null || bytes === 0) return '0 Bytes';const k = 1024;const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];if (bytes < 0) bytes = 0;- // Ensure i is non-negative even for 0 bytes input- const i = bytes === 0 ? 0 : Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));- // Avoid NaN for 0 bytes by checking i before division+ const i = bytes === 0 ? 0 : Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));const size = i === 0 ? bytes : parseFloat((bytes / Math.pow(k, i)).toFixed(2));- return size + ' ' + sizes[i];+ return size + ' ' + sizes[i];+ };++ // Helper for status display+ const formatStatus = (status) => {+ if (!status) return 'Unknown';+ // Capitalize first letter, handle 'SUMMARIZING' specifically+ return status.charAt(0).toUpperCase() + status.slice(1).toLowerCase();+ };++ // Helper for status badge class+ const getStatusClass = (status) => {+ switch(status) {+ case 'PENDING': return 'status-pending';+ case 'PROCESSING': return 'status-processing';+ case 'SUMMARIZING': return 'status-summarizing';+ case 'COMPLETED': return 'status-completed';+ case 'FAILED': return 'status-failed';+ default: return 'status-pending'; // Default or unknown+ }};- // Reset state specific to the processing of a single file+const resetCurrentFileProcessingState = () => {if (pollInterval.value) clearInterval(pollInterval.value);pollInterval.value = null;@@ -485,194 +472,187 @@processingMessage.value = '';};- const switchToUploadView = () => {- // Don't reset processing state here, queue might be active+ const switchToUploadView = () => {currentView.value = 'upload';selectedRecording.value = null;- currentRecording.value = null; // Clear input view data- };+ };const switchToGalleryView = async () => {- // Don't reset processing statecurrentView.value = 'gallery';- // selectedRecording.value = null; // Keep selection? Optional.- // currentRecording.value = null;- await loadRecordings(); // Refresh recordings+ await loadRecordings(); // Refresh recordings when switching back};- // --- Drag and Drop Handlers ---const handleDragLeave = (e) => {- // Prevent dragleave flicker when moving over child elementsif (e.relatedTarget && e.currentTarget.contains(e.relatedTarget)) {return;- }+ }dragover.value = false;}const handleDrop = (e) => {dragover.value = false;addFilesToQueue(e.dataTransfer.files);- // Optionally switch view or just let the popup handle it- // if (currentView.value !== 'gallery') {- // switchToGalleryView();- // }- };+ };const handleFileSelect = (e) => {addFilesToQueue(e.target.files);e.target.value = null; // Reset input- // Optionally switch view- // if (currentView.value !== 'gallery') {- // switchToGalleryView();- // }};// --- Queue Management ---const addFilesToQueue = (files) => {let filesAdded = 0;for (const file of files) {- if (file && file.type.startsWith('audio/')) {- // Check file size client-side- if (file.size > maxFileSizeMB.value * 1024 * 1024) {+ if (file && file.type.startsWith('audio/')) {+ if (file.size > maxFileSizeMB.value * 1024 * 1024) {setGlobalError(`File "${file.name}" exceeds the maximum size of ${maxFileSizeMB.value} MB and was skipped.`);- continue; // Skip this file+ continue;}const clientId = `client-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;- uploadQueue.value.push({- file: file,- status: 'queued',- recordingId: null,- clientId: clientId,- error: null+ uploadQueue.value.push({+ file: file, status: 'queued', recordingId: null, clientId: clientId, error: null});filesAdded++;- } else if (file) {- setGlobalError(`Invalid file type "${file.name}". Only audio files are accepted. File skipped.`);- }+ } else if (file) {+ setGlobalError(`Invalid file type "${file.name}". Only audio files are accepted. File skipped.`);+ }}- if(filesAdded > 0) {+ if(filesAdded > 0) {console.log(`Added ${filesAdded} file(s) to the queue.`);- progressPopupMinimized.value = false; // Show popup when files are added- // Start processing if not already active+ progressPopupMinimized.value = false; // Show popupif (!isProcessingActive.value) {- startProcessingQueue();- }+ startProcessingQueue();+ }}};const startProcessingQueue = async () => {- console.log("Attempting to start processing queue...");- if (isProcessingActive.value) {- console.log("Queue processor already active.");- return; // Already processing- }+ console.log("Attempting to start processing queue...");+ if (isProcessingActive.value) {+ console.log("Queue processor already active.");+ return;+ }- isProcessingActive.value = true;- resetCurrentFileProcessingState(); // Clear state from any previous file+ isProcessingActive.value = true;+ resetCurrentFileProcessingState();const nextFileItem = uploadQueue.value.find(item => item.status === 'queued');- if (nextFileItem) {- console.log(`Processing next file: ${nextFileItem.file.name}`);- currentlyProcessingFile.value = nextFileItem; // Set the reference- nextFileItem.status = 'uploading';- processingMessage.value = 'Preparing upload...';- processingProgress.value = 5;+ if (nextFileItem) {+ console.log(`Processing next file: ${nextFileItem.file.name} (Client ID: ${nextFileItem.clientId})`);+ currentlyProcessingFile.value = nextFileItem;+ nextFileItem.status = 'uploading';+ processingMessage.value = 'Preparing upload...';+ processingProgress.value = 5;- try {- const formData = new FormData();- formData.append('file', nextFileItem.file);+ try {+ const formData = new FormData();+ formData.append('file', nextFileItem.file);- processingMessage.value = 'Uploading file...';- processingProgress.value = 10;+ processingMessage.value = 'Uploading file...';+ processingProgress.value = 10;- const response = await fetch('/upload', { method: 'POST', body: formData });- const data = await response.json();+ const response = await fetch('/upload', { method: 'POST', body: formData });+ const data = await response.json();- if (!response.ok) {- let errorMsg = data.error || `Upload failed with status ${response.status}`;- if (response.status === 413) {- errorMsg = data.error || `File too large. Maximum size: ${data.max_size_mb?.toFixed(0) || maxFileSizeMB.value} MB.`;- }- throw new Error(errorMsg);- }+ if (!response.ok) {+ let errorMsg = data.error || `Upload failed with status ${response.status}`;+ if (response.status === 413) errorMsg = data.error || `File too large. Max: ${data.max_size_mb?.toFixed(0) || maxFileSizeMB.value} MB.`;+ throw new Error(errorMsg);+ }if (response.status === 202 && data.id) {- console.log(`File ${nextFileItem.file.name} uploaded. Recording ID: ${data.id}. Starting transcription poll.`);- nextFileItem.status = 'processing';- nextFileItem.recordingId = data.id;- processingMessage.value = 'Upload complete. Starting transcription...';- processingProgress.value = 30;+ console.log(`File ${nextFileItem.file.name} uploaded. Recording ID: ${data.id}. Starting status poll.`);+ // Status is now 'PENDING' on backend, will be updated by poll+ nextFileItem.status = 'pending'; // Reflect initial backend status+ nextFileItem.recordingId = data.id;+ processingMessage.value = 'Upload complete. Waiting for processing...';+ processingProgress.value = 30;// Add preliminary record to gallery immediately- recordings.value.unshift(data);- if (!selectedRecording.value) {- // Optionally select the new item if nothing is selected- // selectRecording(data);- }+ recordings.value.unshift(data);+ // Optionally select the new item+ // selectRecording(data);++ pollProcessingStatus(nextFileItem); // Start polling- // Start polling for this specific file- pollProcessingStatus(nextFileItem);+ } else {+ throw new Error('Unexpected success response from server after upload.');+ }+ } catch (error) {+ console.error(`Upload/Processing Error for ${nextFileItem.file.name} (Client ID: ${nextFileItem.clientId}):`, error);+ nextFileItem.status = 'failed';+ nextFileItem.error = error.message;+ // Find the potentially added preliminary record and mark it failed+ const failedRecordIndex = recordings.value.findIndex(r => r.id === nextFileItem.recordingId);+ if(failedRecordIndex !== -1) {+ recordings.value[failedRecordIndex].status = 'FAILED';+ recordings.value[failedRecordIndex].transcription = `Upload/Processing failed: ${error.message}`;} else {- throw new Error('Unexpected success response from server after upload.');+ // If record wasn't even created, add a note+ setGlobalError(`Failed to process "${nextFileItem.file.name}": ${error.message}`);}- } catch (error) {- console.error(`Upload/Processing Error for ${nextFileItem.file.name}:`, error);- nextFileItem.status = 'failed';- nextFileItem.error = error.message;- setGlobalError(`Failed to process "${nextFileItem.file.name}": ${error.message}`);- // Reset state and immediately try the next file+ // Reset state and try next fileresetCurrentFileProcessingState();- isProcessingActive.value = false; // Allow the processor to restart- await nextTick(); // Ensure state updates before recursing- startProcessingQueue(); // Try next file+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue();}- } else {- console.log("Upload queue is empty or no files are queued.");- isProcessingActive.value = false; // No more files to process- // Optional: Auto-minimize popup after a delay when queue finishes+ } else {+ console.log("Upload queue is empty or no files are queued.");+ isProcessingActive.value = false;+ // Optional: Auto-minimize popup after a delay// setTimeout(() => {- // if (uploadQueue.value.every(f => f.status === 'completed' || f.status === 'failed')) {- // progressPopupMinimized.value = true;- // }+ // if (!isProcessingActive.value && uploadQueue.value.every(f => ['completed', 'failed'].includes(f.status))) {+ // progressPopupMinimized.value = true;+ // }// }, 5000);- }- };-+ }+ };const pollProcessingStatus = (fileItem) => {- if (pollInterval.value) clearInterval(pollInterval.value); // Clear existing before starting new+ if (pollInterval.value) clearInterval(pollInterval.value);const recordingId = fileItem.recordingId;if (!recordingId) {console.error("Cannot poll status without recording ID for", fileItem.file.name);- fileItem.status = 'failed';- fileItem.error = 'Internal error: Missing recording ID for polling.';- resetCurrentFileProcessingState();- isProcessingActive.value = false;- nextTick(startProcessingQueue); // Try next file+ fileItem.status = 'failed';+ fileItem.error = 'Internal error: Missing recording ID for polling.';+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ nextTick(startProcessingQueue); // Try next filereturn;}- processingMessage.value = 'Transcription queued...';+ // Initial message based on fileItem status (should be 'pending' initially)+ processingMessage.value = 'Waiting for transcription...';processingProgress.value = 40;pollInterval.value = setInterval(async () => {- if (fileItem.status !== 'processing') {- // If status changed elsewhere (e.g., user cancelled), stop polling+ // Check if the item is still the one being processed and hasn't finished/failed+ if (!currentlyProcessingFile.value || currentlyProcessingFile.value.clientId !== fileItem.clientId || ['completed', 'failed'].includes(fileItem.status)) {+ console.log(`Polling stopped for ${fileItem.clientId} as it's no longer active or finished.`);clearInterval(pollInterval.value);pollInterval.value = null;+ // If this was the active file, allow queue to restart+ if (currentlyProcessingFile.value && currentlyProcessingFile.value.clientId === fileItem.clientId) {+ resetCurrentFileProcessingState();+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue();+ }return;}+try {console.log(`Polling status for recording ID: ${recordingId} (${fileItem.file.name})`);const response = await fetch(`/status/${recordingId}`);if (!response.ok) throw new Error(`Status check failed with status ${response.status}`);const data = await response.json();- const galleryIndex = recordings.value.findIndex(r => r.id === recordingId);+ const galleryIndex = recordings.value.findIndex(r => r.id === recordingId);// Update item in the main recordings listif (galleryIndex !== -1) {@@ -682,64 +662,73 @@}}+ // Update the status in the uploadQueue item as well+ fileItem.status = data.status;++ // Update progress display based on backend statusif (data.status === 'COMPLETED') {- console.log(`Transcription COMPLETED for ${fileItem.file.name} (ID: ${recordingId})`);- processingMessage.value = 'Transcription complete!';+ console.log(`Processing COMPLETED for ${fileItem.file.name} (ID: ${recordingId})`);+ processingMessage.value = 'Processing complete!';processingProgress.value = 100;- fileItem.status = 'completed';- // Clear polling and processing state for this file+ fileItem.status = 'completed'; // Final status for queue item+ // Stop polling, reset state, and trigger next item+ clearInterval(pollInterval.value);+ pollInterval.value = null;resetCurrentFileProcessingState();- isProcessingActive.value = false; // Allow processor to check for next file+ isProcessingActive.value = false;await nextTick();- startProcessingQueue(); // Process the next file in the queue+ startProcessingQueue();} else if (data.status === 'FAILED') {- console.log(`Transcription FAILED for ${fileItem.file.name} (ID: ${recordingId})`);- processingMessage.value = 'Transcription failed.';- processingProgress.value = 100; // Show progress done, but failed state- fileItem.status = 'failed';- fileItem.error = data.transcription || 'Transcription failed on server.';- setGlobalError(`Transcription failed for "${data.title || fileItem.file.name}".`);- // Clear polling and processing state for this file+ console.log(`Processing FAILED for ${fileItem.file.name} (ID: ${recordingId})`);+ processingMessage.value = 'Processing failed.';+ processingProgress.value = 100; // Show 100% but failed state+ fileItem.status = 'failed'; // Final status for queue item+ fileItem.error = data.transcription || data.summary || 'Processing failed on server.';+ setGlobalError(`Processing failed for "${data.title || fileItem.file.name}".`);+ // Stop polling, reset state, and trigger next item+ clearInterval(pollInterval.value);+ pollInterval.value = null;resetCurrentFileProcessingState();- isProcessingActive.value = false; // Allow processor to check for next file+ isProcessingActive.value = false;await nextTick();- startProcessingQueue(); // Process the next file in the queue+ startProcessingQueue();} else if (data.status === 'PROCESSING') {processingMessage.value = 'Transcription in progress...';- // Simulate some progress visually, as backend doesn't give percentage- processingProgress.value = Math.min(95, processingProgress.value + Math.random() * 5);+ processingProgress.value = Math.min(65, processingProgress.value + Math.random() * 5); // Mid-range progress+ } else if (data.status === 'SUMMARIZING') {+ processingMessage.value = 'Generating title & summary...';+ processingProgress.value = Math.min(95, processingProgress.value + Math.random() * 5); // Higher progress} else { // PENDING- processingMessage.value = 'Waiting for transcription to start...';+ processingMessage.value = 'Waiting in queue...';processingProgress.value = 45; // Keep progress indication while pending}} catch (error) {console.error(`Polling Error for ${fileItem.file.name} (ID: ${recordingId}):`, error);+ // Assume failed if polling error occursfileItem.status = 'failed';fileItem.error = `Error checking status: ${error.message}`;- setGlobalError(`Error checking status for "${fileItem.file.name}": ${error.message}.`);+ setGlobalError(`Error checking status for "${fileItem.file.name}": ${error.message}.`);+ // Update record in gallery if found+ const galleryIndex = recordings.value.findIndex(r => r.id === recordingId);+ if (galleryIndex !== -1) recordings.value[galleryIndex].status = 'FAILED';++ clearInterval(pollInterval.value);+ pollInterval.value = null;resetCurrentFileProcessingState();- isProcessingActive.value = false; // Allow processor to check for next file- await nextTick();- startProcessingQueue(); // Process the next file in the queue+ isProcessingActive.value = false;+ await nextTick();+ startProcessingQueue(); // Process the next file}- }, 4000); // Poll every 4 seconds+ }, 5000); // Poll every 5 seconds (adjust as needed)};- // --- Gallery and Detail Methods (Largely Unchanged) ---- const autoSave = () => {- clearTimeout(autoSaveTimeout.value);- autoSaveTimeout.value = setTimeout(() => {- // Save applies to currently selected gallery item OR the 'input' view item- const itemToSave = currentView.value === 'input' ? currentRecording.value : selectedRecording.value;- if (itemToSave) {- saveMetadata(itemToSave);- }- }, 1200);- };+ // --- Gallery and Detail Methods ---+ // AutoSave removed in favor of explicit save in modal+ // const autoSave = () => { ... };- const saveMetadata = async (recordingDataToSave) => {+ const saveMetadata = async (recordingDataToSave) => {globalError.value = null;if (!recordingDataToSave || !recordingDataToSave.id) return null;console.log('Saving metadata for:', recordingDataToSave.id);@@ -748,7 +737,8 @@id: recordingDataToSave.id,title: recordingDataToSave.title,participants: recordingDataToSave.participants,- notes: recordingDataToSave.notes+ notes: recordingDataToSave.notes,+ summary: recordingDataToSave.summary // <-- ADDED: Include summary};const response = await fetch('/save', {method: 'POST',@@ -762,18 +752,20 @@// Update the master recordings listconst index = recordings.value.findIndex(r => r.id === data.recording.id);if (index !== -1) {- // Update only the fields that were saved, preserve others like status/transcription- recordings.value[index] = { ...recordings.value[index], ...payload };- }+ // Update only the editable fields, preserve others like status/transcription from backend+ recordings.value[index].title = payload.title;+ recordings.value[index].participants = payload.participants;+ recordings.value[index].notes = payload.notes;+ recordings.value[index].summary = payload.summary;+ }// Update selected if it's the one being saved- if (selectedRecording.value?.id === data.recording.id) {- selectedRecording.value = { ...selectedRecording.value, ...payload };- }- // Update input view model if it's the one being saved- if (currentRecording.value?.id === data.recording.id) {- currentRecording.value = { ...currentRecording.value, ...payload };+ if (selectedRecording.value?.id === data.recording.id) {+ selectedRecording.value.title = payload.title;+ selectedRecording.value.participants = payload.participants;+ selectedRecording.value.notes = payload.notes;+ selectedRecording.value.summary = payload.summary;}- return data.recording;+ return data.recording; // Return the full updated object from backend} catch (error) {console.error('Save Metadata Error:', error);setGlobalError(`Save failed: ${error.message}`);@@ -782,7 +774,7 @@};const loadRecordings = async () => {- globalError.value = null;+ globalError.value = null;isLoadingRecordings.value = true;try {const response = await fetch('/recordings');@@ -790,35 +782,54 @@if (!response.ok) throw new Error(data.error || 'Failed to load recordings');recordings.value = data;- // Check for recordings stuck in processing state on load- // This is less critical now as the queue handles restarts, but keep as fallback- const processingOrPending = recordings.value.find(r => (r.status === 'PENDING' || r.status === 'PROCESSING'));- if (processingOrPending && !isProcessingActive.value) {- // Find the corresponding item in uploadQueue if it exists (unlikely on reload)- let queueItem = uploadQueue.value.find(item => item.recordingId === processingOrPending.id);- if (!queueItem) {- // If not in queue (likely page reload), create a placeholder to track polling- console.warn(`Found processing recording ${processingOrPending.id} on load, not in queue. Re-attaching poll.`);- queueItem = {- file: { name: processingOrPending.title, size: processingOrPending.file_size }, // Mock file object- status: processingOrPending.status,- recordingId: processingOrPending.id,- clientId: `reload-${processingOrPending.id}`,- error: null- };- // Don't add to visual queue, just use for polling logic- currentlyProcessingFile.value = queueItem; // Track it- isProcessingActive.value = true; // Mark as active- pollProcessingStatus(queueItem);- } else if(queueItem.status === 'queued' || queueItem.status === 'uploading') {- // If it's somehow in the queue but backend says processing, update queue state- console.log(`Correcting queue status for ${queueItem.clientId} based on loaded data`);- queueItem.status = processingOrPending.status; // 'processing' or 'pending'- queueItem.recordingId = processingOrPending.id;- if (!isProcessingActive.value) { // Start processing if needed- startProcessingQueue();- }- }+ // On load, check for any recordings stuck in PENDING, PROCESSING, or SUMMARIZING+ // and ensure polling is active if the queue processor isn't running.+ const incompleteRecordings = recordings.value.filter(r => ['PENDING', 'PROCESSING', 'SUMMARIZING'].includes(r.status));++ if (incompleteRecordings.length > 0 && !isProcessingActive.value) {+ console.warn(`Found ${incompleteRecordings.length} incomplete recording(s) on load. Attempting to resume polling if not already queued.`);+ for (const recording of incompleteRecordings) {+ // Is this item already being tracked in the queue?+ let queueItem = uploadQueue.value.find(item => item.recordingId === recording.id);+ if (!queueItem) {+ // If not in queue (likely page reload), create a placeholder to track polling+ console.log(`Re-attaching poll for recording ${recording.id}.`);+ queueItem = {+ // Mock file object, size might be useful for display+ file: { name: recording.title || `Recording ${recording.id}`, size: recording.file_size },+ status: recording.status, // Use current status from DB+ recordingId: recording.id,+ clientId: `reload-${recording.id}`, // Unique ID for tracking+ error: null+ };+ // Add to the *beginning* of the visual queue *if* we want to show it there+ // Or just manage polling without adding to queue visually?+ // Let's add it to the queue for consistency in management.+ uploadQueue.value.unshift(queueItem);+ // Start processing queue if it wasn't active+ if (!isProcessingActive.value) {+ startProcessingQueue();+ } else if (currentlyProcessingFile.value?.recordingId !== recording.id) {+ // If processor is active but on a different file, just ensure polling starts+ // Note: startProcessingQueue handles finding the next 'queued'. This item+ // might not be 'queued'. We need direct polling.+ // Let's rethink: The queue processor should handle finding PENDING/PROCESSING items.+ // For simplicity, let's just trigger the queue processor. It will find this item if it's next.+ // If something else is truly processing, this won't interrupt.+ console.log("Triggering queue processor check due to reloaded incomplete item.")+ // Ensure it's marked conceptually 'queued' for the processor to pick up+ queueItem.status = 'queued';+ startProcessingQueue(); // Let the queue logic handle it+ }++ } else if (queueItem.status !== recording.status && !['completed', 'failed'].includes(queueItem.status)) {+ // If queue status differs from DB, update queue status+ console.log(`Correcting queue status for ${queueItem.clientId} from ${queueItem.status} to ${recording.status}`);+ queueItem.status = recording.status;+ // Restart queue processing if needed+ if (!isProcessingActive.value) startProcessingQueue();+ }+ }}} catch (error) {@@ -826,28 +837,19 @@setGlobalError(`Failed to load recordings: ${error.message}`);recordings.value = [];} finally {- isLoadingRecordings.value = false;+ isLoadingRecordings.value = false;}};- const selectRecording = (recording) => {+ const selectRecording = (recording) => {selectedRecording.value = recording;- // If the selected item is still processing according to gallery data,- // ensure polling is active for it if needed (usually handled by queue)- if((recording.status === 'PENDING' || recording.status === 'PROCESSING') && !currentlyProcessingFile.value && !isProcessingActive.value) {- console.warn("Selected a processing item, but queue isn't active. Attempting to resume poll.");- let queueItem = uploadQueue.value.find(item => item.recordingId === recording.id);- if (!queueItem) {- queueItem = { file: { name: recording.title, size: recording.file_size }, status: recording.status, recordingId: recording.id, clientId: `select-${recording.id}`, error: null };- currentlyProcessingFile.value = queueItem;- isProcessingActive.value = true;- pollProcessingStatus(queueItem);- }- }- };+ // Optional: Check if polling needs to be restarted if user selects an incomplete item+ // This logic is complex and might be redundant with the loadRecordings check.+ // Let's rely on loadRecordings and the queue processor for robustness.+ };const editRecording = (recording) => {- // Create a deep copy for editing to avoid modifying original reactive object directly+ // Create a deep copy for the modal to prevent modifying original object directlyeditingRecording.value = JSON.parse(JSON.stringify(recording));showEditModal.value = true;};@@ -857,14 +859,14 @@editingRecording.value = null;};- const saveEdit = async () => {- // Save using the saveMetadata function which updates the main list- const updatedRecordingData = await saveMetadata(editingRecording.value);- if (updatedRecordingData) {- cancelEdit(); // Close modal on success+ const saveEdit = async () => {+ // Save using the saveMetadata function which updates the main list & selected item+ const success = await saveMetadata(editingRecording.value);+ if (success) {+ cancelEdit(); // Close modal on success}// Keep modal open on failure, error shown via globalError- };+ };const confirmDelete = (recording) => {recordingToDelete.value = recording;@@ -880,56 +882,61 @@globalError.value = null;if (!recordingToDelete.value) return;const idToDelete = recordingToDelete.value.id;+ const titleToDelete = recordingToDelete.value.title; // For logging/messagingtry {const response = await fetch(`/recording/${idToDelete}`, { method: 'DELETE' });const data = await response.json();if (!response.ok) throw new Error(data.error || 'Failed to delete recording');- // Remove from gallery list+ // Remove from gallery listrecordings.value = recordings.value.filter(r => r.id !== idToDelete);- // Remove from upload queue if it exists there- uploadQueue.value = uploadQueue.value.filter(item => item.recordingId !== idToDelete);- if (selectedRecording.value?.id === idToDelete) selectedRecording.value = null;- if (currentRecording.value?.id === idToDelete) currentRecording.value = null;- if (currentlyProcessingFile.value?.recordingId === idToDelete) {+ // Find and remove from upload queue+ const queueIndex = uploadQueue.value.findIndex(item => item.recordingId === idToDelete);+ if (queueIndex !== -1) {+ const deletedItem = uploadQueue.value.splice(queueIndex, 1)[0];+ console.log(`Removed item ${deletedItem.clientId} from queue.`);// If deleting the file currently being processed, stop polling and move to next- console.log("Deleting currently processing file. Stopping poll and moving to next.");- resetCurrentFileProcessingState();- isProcessingActive.value = false;- await nextTick();- startProcessingQueue();- }+ if (currentlyProcessingFile.value?.clientId === deletedItem.clientId) {+ console.log(`Deleting currently processing file: ${titleToDelete}. Stopping poll and moving to next.`);+ clearInterval(pollInterval.value); // Stop polling explicitly+ pollInterval.value = null;+ resetCurrentFileProcessingState();+ isProcessingActive.value = false; // Allow queue to restart+ await nextTick();+ startProcessingQueue();+ }+ }++ if (selectedRecording.value?.id === idToDelete) selectedRecording.value = null;cancelDelete();+ console.log(`Successfully deleted recording ${idToDelete} (${titleToDelete})`);+} catch (error) {console.error('Delete Error:', error);- setGlobalError(`Failed to delete recording: ${error.message}`);+ setGlobalError(`Failed to delete recording "${titleToDelete}": ${error.message}`);cancelDelete(); // Still close modal on error}};-// --- Lifecycle Hooks ---onMounted(() => {loadRecordings();- // fetch('/config').then(res => res.json()).then(cfg => maxFileSizeMB.value = cfg.max_size_mb);});// --- Watchers ---watch(uploadQueue, (newQueue, oldQueue) => {- // If the queue becomes empty, potentially hide or minimize the popup after a delay- if (newQueue.length === 0 && oldQueue.length > 0) {- console.log("Upload queue is now empty.");- isProcessingActive.value = false; // Ensure processor stops- // Maybe auto-minimize after a short delay- // setTimeout(() => progressPopupMinimized.value = true, 3000);- }- }, { deep: true }); // Deep watch needed to detect status changes within items+ if (newQueue.length === 0 && oldQueue.length > 0 && !isProcessingActive.value) {+ console.log("Upload queue processing finished.");+ // Optional: Auto-minimize after delay+ // setTimeout(() => progressPopupMinimized.value = true, 3000);+ }+ }, { deep: true });return {// State- currentView, dragover, recordings, selectedRecording, currentRecording,+ currentView, dragover, recordings, selectedRecording, // currentRecording removedshowEditModal, showDeleteModal, editingRecording, recordingToDelete,isLoadingRecordings, globalError, maxFileSizeMB,// Multi-upload State@@ -938,15 +945,13 @@// ComputedgroupedRecordings, totalInQueue, completedInQueue, queuedFiles, finishedFilesInQueue,// Methods- handleDrop, handleFileSelect, autoSave, loadRecordings,+ handleDrop, handleFileSelect, /*autoSave removed*/ loadRecordings,selectRecording, editRecording, cancelEdit, saveEdit, confirmDelete,cancelDelete, deleteRecording, switchToUploadView, switchToGalleryView,- formatFileSize, setGlobalError, handleDragLeave,- // Queue Methods (exposed if needed, but mainly internal)- // addFilesToQueue, startProcessingQueue, pollProcessingStatus- }+ formatFileSize, setGlobalError, handleDragLeave, formatStatus, getStatusClass,+ }},- delimiters: ['${', '}'] // Use different delimiters to avoid Flask conflict+ delimiters: ['${', '}'] // Keep Vue delimiters distinct from Flask's Jinja}).mount('#app');</script>