diff --git a/.railwayignore b/.railwayignore new file mode 100644 index 0000000..d2bc1b0 --- /dev/null +++ b/.railwayignore @@ -0,0 +1,28 @@ +# Railway ignore file - prevent large files from being included in build +node_modules/.bin +node_modules/.cache +node_modules/.vite +.next +.nuxt +dist +build +*.log +.DS_Store +.env.local +.venv +venv +__pycache__ +*.pyc +.pytest_cache +.coverage +.git +.github +notebooks +tests +data +*.png +*.svg +.flake8 +.pre-commit-config.yaml +CHANGELOG.md +model-card.md diff --git a/farsi_transcriber_web/backend/app.py b/farsi_transcriber_web/backend/app.py index 6147803..7675651 100644 --- a/farsi_transcriber_web/backend/app.py +++ b/farsi_transcriber_web/backend/app.py @@ -2,7 +2,7 @@ Farsi Transcriber Backend API Flask API for handling audio/video file transcription using Whisper model. -Configured for Railway deployment. +Configured for Railway deployment with lazy model loading. """ import os @@ -10,10 +10,12 @@ import sys import tempfile from pathlib import Path from werkzeug.utils import secure_filename -import whisper from flask import Flask, request, jsonify from flask_cors import CORS +# Prevent model download during build +os.environ['WHISPER_CACHE'] = os.path.expanduser('~/.cache/whisper') + # Add parent directory to path for imports sys.path.insert(0, str(Path(__file__).parent.parent.parent)) @@ -30,15 +32,18 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['MAX_CONTENT_LENGTH'] = MAX_FILE_SIZE app.config['ENV'] = os.getenv('FLASK_ENV', 'production') -# Load Whisper model (lazy load for faster startup) +# Load Whisper model (lazy load - only on first transcription request) model = None def load_model(): - """Lazy load Whisper model on first use""" + """Lazy load Whisper model on first use (not during build)""" global model if model is None: try: - print("Loading Whisper model...") + print("⏳ Loading Whisper model for first time...") + print(" This may take 1-2 minutes on first run...") + # Import here to avoid loading during build + import whisper model = whisper.load_model('medium') print("✓ Whisper model loaded successfully") except Exception as e: diff --git a/farsi_transcriber_web/backend/requirements.txt b/farsi_transcriber_web/backend/requirements.txt index 745e549..29b263a 100644 --- a/farsi_transcriber_web/backend/requirements.txt +++ b/farsi_transcriber_web/backend/requirements.txt @@ -2,8 +2,9 @@ Flask==2.3.3 Flask-CORS==4.0.0 python-dotenv==1.0.0 openai-whisper>=20230314 -torch>=1.10.1 +torch>=1.10.1,<2.0 numpy>=1.21.0 python-multipart==0.0.6 gunicorn==21.2.0 +