Skip to content

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

Python

Fix all import paths after repository reorganization

Murtaza Nasir0468ac8863f2
diff --git a/scripts/create_admin.py b/scripts/create_admin.py
index 3ff374de..efeed17a 100644
--- a/scripts/create_admin.py
+++ b/scripts/create_admin.py
@@ -19,7 +19,7 @@ try:
except (RuntimeError, AttributeError, KeyError):
# If not in app context, import directly
try:
- from app import app, db, User, bcrypt
+ from src.app import app, db, User, bcrypt
except ImportError as e:
print(f"Error: Could not import required modules: {e}")
print("Make sure create_admin.py is runnable and PYTHONPATH is set.")
diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh
index decda695..8da7d0db 100644
--- a/scripts/docker-entrypoint.sh
+++ b/scripts/docker-entrypoint.sh
@@ -8,11 +8,11 @@ chmod 755 /data/uploads /data/instance
# Initialize the database if it doesn't exist
if [ ! -f /data/instance/transcriptions.db ]; then
echo "Database doesn't exist. Creating new database..."
- python -c "from app import app, db; app.app_context().push(); db.create_all()"
+ python -c "from src.app import app, db; app.app_context().push(); db.create_all()"
echo "Database created successfully."
else
echo "Database exists. Checking for schema updates..."
- python -c "from app import app; app.app_context().push()"
+ python -c "from src.app import app; app.app_context().push()"
fi
# Check if we need to create an admin user (regardless of whether the database exists)
diff --git a/scripts/docker_create_admin.py b/scripts/docker_create_admin.py
index fcfba548..3acc3cf8 100644
--- a/scripts/docker_create_admin.py
+++ b/scripts/docker_create_admin.py
@@ -18,7 +18,7 @@ try:
except (RuntimeError, AttributeError, KeyError):
# If not in app context, import directly
try:
- from app import app, db, User, bcrypt
+ from src.app import app, db, User, bcrypt
except ImportError as e:
print(f"Error: Could not import required modules: {e}")
print("Make sure docker_create_admin.py is runnable and PYTHONPATH is set.")
diff --git a/scripts/migrate_existing_recordings.py b/scripts/migrate_existing_recordings.py
index 83bb311a..203ea006 100644
--- a/scripts/migrate_existing_recordings.py
+++ b/scripts/migrate_existing_recordings.py
@@ -5,7 +5,7 @@ This script will chunk and vectorize all existing recordings that haven't been p
"""
import os
import sys
-from app import app, db, Recording, TranscriptChunk, process_recording_chunks
+from src.app import app, db, Recording, TranscriptChunk, process_recording_chunks
def count_recordings_needing_processing():
"""Count how many recordings need chunk processing."""
diff --git a/scripts/reset_db.py b/scripts/reset_db.py
index 08f72e61..240fc7a3 100644
--- a/scripts/reset_db.py
+++ b/scripts/reset_db.py
@@ -24,7 +24,7 @@ except (RuntimeError, AttributeError, KeyError):
# If not in app context, import directly
try:
# Ensure this import reflects the updated app.py with the new model
- from app import app, db
+ from src.app import app, db
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.")
diff --git a/src/app.py b/src/app.py
index e1a2b7a8..7a60eca7 100644
--- a/src/app.py
+++ b/src/app.py
@@ -46,7 +46,7 @@ import ast
import logging
import secrets
import time
-from audio_chunking import AudioChunkingService, ChunkProcessingError, ChunkingNotSupportedError
+from src.audio_chunking import AudioChunkingService, ChunkProcessingError, ChunkingNotSupportedError
# Optional imports for embedding functionality
try:
@@ -552,7 +552,9 @@ def process_streaming_with_thinking(stream):
# Signal the end of the stream
yield f"data: {json.dumps({'end_of_stream': True})}\n\n"
-app = Flask(__name__)
+app = Flask(__name__,
+ template_folder='../templates',
+ static_folder='../static')
# Use environment variables or default paths for Docker compatibility
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:////data/instance/transcriptions.db')
app.config['UPLOAD_FOLDER'] = os.environ.get('UPLOAD_FOLDER', '/data/uploads')
@@ -6206,7 +6208,7 @@ def initialize_file_monitor():
"""Initialize file monitor after app is fully loaded to avoid circular imports."""
try:
# Import here to avoid circular imports
- import file_monitor
+ import src.file_monitor as file_monitor
file_monitor.start_file_monitor()
app.logger.info("File monitor initialization completed")
except Exception as e:
@@ -6215,7 +6217,7 @@ def initialize_file_monitor():
def get_file_monitor_functions():
"""Get file monitor functions, handling import errors gracefully."""
try:
- import file_monitor
+ import src.file_monitor as file_monitor
return file_monitor.start_file_monitor, file_monitor.stop_file_monitor, file_monitor.get_file_monitor_status
except ImportError as e:
app.logger.warning(f"File monitor not available: {e}")
diff --git a/src/file_monitor.py b/src/file_monitor.py
index c57a44ba..15e5ac63 100644
--- a/src/file_monitor.py
+++ b/src/file_monitor.py
@@ -81,7 +81,7 @@ class FileMonitor:
return
# Import Flask components inside function to avoid circular imports
- from app import app, db, User
+ from src.app import app, db, User
with app.app_context():
try:
@@ -275,7 +275,7 @@ class FileMonitor:
user_id (int): ID of the user to assign the recording to
"""
# Import Flask components inside function to avoid circular imports
- from app import app, db, Recording, User, transcribe_audio_task
+ from src.app import app, db, Recording, User, transcribe_audio_task
with app.app_context():
try:
@@ -419,7 +419,7 @@ def start_file_monitor():
return
# Import Flask app inside function to avoid circular imports
- from app import app
+ from src.app import app
# Get configuration from environment
watch_dir = os.environ.get('AUTO_PROCESS_WATCH_DIR', '/data/auto-process')
diff --git a/tests/test_inquire_mode.py b/tests/test_inquire_mode.py
index cf6ea17d..539766f7 100644
--- a/tests/test_inquire_mode.py
+++ b/tests/test_inquire_mode.py
@@ -8,7 +8,7 @@ import sys
# Add the parent directory to the path to import app
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from app import app, db, User, Recording, TranscriptChunk, InquireSession, Tag
+from src.app import app, db, User, Recording, TranscriptChunk, InquireSession, Tag
def test_database_models():
"""Test that the new database models work correctly."""
@@ -91,7 +91,7 @@ def test_chunking_functions():
print("🔧 Testing Chunking Functions...")
try:
- from app import chunk_transcription, generate_embeddings, serialize_embedding, deserialize_embedding
+ from src.app import chunk_transcription, generate_embeddings, serialize_embedding, deserialize_embedding
# Test chunking
test_text = "This is a test sentence. This is another sentence for testing. And here's a third sentence to make sure chunking works properly with longer text that should be split into multiple chunks."
@@ -133,7 +133,7 @@ def test_api_imports():
print("🔌 Testing API Endpoint Imports...")
try:
- from app import (
+ from src.app import (
get_inquire_sessions, create_inquire_session, inquire_search,
inquire_chat, get_available_filters, process_recording_chunks_endpoint
)
diff --git a/tests/test_json_fix.py b/tests/test_json_fix.py
index d0054ce4..9fe148c9 100644
--- a/tests/test_json_fix.py
+++ b/tests/test_json_fix.py
@@ -5,7 +5,7 @@ import os
# Add the parent directory to the path to import app
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from app import auto_close_json, safe_json_loads
+from src.app import auto_close_json, safe_json_loads
def run_tests():
"""Runs a series of tests for the JSON fixing functions."""
diff --git a/tests/test_json_preprocessing.py b/tests/test_json_preprocessing.py
index 436c5d69..d3161433 100644
--- a/tests/test_json_preprocessing.py
+++ b/tests/test_json_preprocessing.py
@@ -22,7 +22,7 @@ class MockApp:
app = MockApp()
# Import the functions we want to test
-from app import safe_json_loads, preprocess_json_escapes, extract_json_object
+from src.app import safe_json_loads, preprocess_json_escapes, extract_json_object
class TestJSONPreprocessing(unittest.TestCase):
"""Test cases for JSON preprocessing functionality."""