Spaces:
Running
Running
Commit
·
c27f115
1
Parent(s):
0caca00
Refactor model structure: update import paths from 'app.modelz' to 'app.models' across multiple files for consistency, remove obsolete 'modelz' directory, and adjust Dockerfile and migration script to reflect these changes, enhancing clarity and organization in the codebase.
Browse files- Dockerfile +3 -2
- alembic/env.py +1 -1
- app/api/audiobook_routes.py +1 -1
- app/api/routes.py +1 -1
- app/api/streaming.py +1 -1
- app/db.py +1 -1
- app/generator.py +1 -1
- app/main.py +1 -1
- app/modelz/__init__.py +0 -10
- app/modelz/database.py +0 -80
- app/voice_cloning.py +1 -1
- app/voice_enhancement.py +1 -1
- app/voice_memory.py +1 -1
- scripts/migrate.py +7 -7
Dockerfile
CHANGED
@@ -19,7 +19,8 @@ RUN apt-get update && apt-get install -y \
|
|
19 |
# Create necessary directories first
|
20 |
RUN mkdir -p /app/storage/audio \
|
21 |
/app/storage/text \
|
22 |
-
/app/storage/temp
|
|
|
23 |
|
24 |
# Copy requirements first to leverage Docker cache
|
25 |
COPY requirements.txt .
|
@@ -34,7 +35,7 @@ COPY . .
|
|
34 |
# Debug: Show destination directory structure
|
35 |
RUN echo "Contents of /app:" && ls -la /app && \
|
36 |
echo "\nContents of /app/app:" && ls -la /app/app && \
|
37 |
-
echo "\nContents of /app/app/
|
38 |
|
39 |
# Set up permissions
|
40 |
RUN chmod +x /app/scripts/run.sh && \
|
|
|
19 |
# Create necessary directories first
|
20 |
RUN mkdir -p /app/storage/audio \
|
21 |
/app/storage/text \
|
22 |
+
/app/storage/temp \
|
23 |
+
/app/app/models
|
24 |
|
25 |
# Copy requirements first to leverage Docker cache
|
26 |
COPY requirements.txt .
|
|
|
35 |
# Debug: Show destination directory structure
|
36 |
RUN echo "Contents of /app:" && ls -la /app && \
|
37 |
echo "\nContents of /app/app:" && ls -la /app/app && \
|
38 |
+
echo "\nContents of /app/app/models:" && ls -la /app/app/models
|
39 |
|
40 |
# Set up permissions
|
41 |
RUN chmod +x /app/scripts/run.sh && \
|
alembic/env.py
CHANGED
@@ -5,7 +5,7 @@ from sqlalchemy import pool
|
|
5 |
|
6 |
from alembic import context
|
7 |
|
8 |
-
from app.
|
9 |
from app.config import get_settings
|
10 |
|
11 |
# this is the Alembic Config object, which provides
|
|
|
5 |
|
6 |
from alembic import context
|
7 |
|
8 |
+
from app.models.database import Base
|
9 |
from app.config import get_settings
|
10 |
|
11 |
# this is the Alembic Config object, which provides
|
app/api/audiobook_routes.py
CHANGED
@@ -11,7 +11,7 @@ from typing import Optional, List
|
|
11 |
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks, UploadFile, File, Form, Depends
|
12 |
from fastapi.responses import FileResponse, JSONResponse
|
13 |
from sqlalchemy.orm import Session
|
14 |
-
from app.
|
15 |
from app.services.storage import storage
|
16 |
from app.db import get_db
|
17 |
import torchaudio
|
|
|
11 |
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks, UploadFile, File, Form, Depends
|
12 |
from fastapi.responses import FileResponse, JSONResponse
|
13 |
from sqlalchemy.orm import Session
|
14 |
+
from app.models.database import Audiobook, AudiobookStatus, AudiobookChunk, TextChunk
|
15 |
from app.services.storage import storage
|
16 |
from app.db import get_db
|
17 |
import torchaudio
|
app/api/routes.py
CHANGED
@@ -16,7 +16,7 @@ import numpy as np
|
|
16 |
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks, Body, Response, Query
|
17 |
from fastapi.responses import StreamingResponse
|
18 |
from app.api.schemas import SpeechRequest, ResponseFormat, Voice
|
19 |
-
from app.
|
20 |
from app.api.streaming import AudioChunker
|
21 |
from app.prompt_engineering import split_into_segments
|
22 |
|
|
|
16 |
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks, Body, Response, Query
|
17 |
from fastapi.responses import StreamingResponse
|
18 |
from app.api.schemas import SpeechRequest, ResponseFormat, Voice
|
19 |
+
from app.model import Segment
|
20 |
from app.api.streaming import AudioChunker
|
21 |
from app.prompt_engineering import split_into_segments
|
22 |
|
app/api/streaming.py
CHANGED
@@ -10,7 +10,7 @@ from fastapi import APIRouter, Request, HTTPException
|
|
10 |
from fastapi.responses import StreamingResponse
|
11 |
from app.api.schemas import SpeechRequest, ResponseFormat
|
12 |
from app.prompt_engineering import split_into_segments
|
13 |
-
from app.
|
14 |
|
15 |
logger = logging.getLogger(__name__)
|
16 |
router = APIRouter()
|
|
|
10 |
from fastapi.responses import StreamingResponse
|
11 |
from app.api.schemas import SpeechRequest, ResponseFormat
|
12 |
from app.prompt_engineering import split_into_segments
|
13 |
+
from app.model import Segment
|
14 |
|
15 |
logger = logging.getLogger(__name__)
|
16 |
router = APIRouter()
|
app/db.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
import os
|
3 |
from sqlalchemy import create_engine
|
4 |
from sqlalchemy.orm import sessionmaker
|
5 |
-
from app.
|
6 |
|
7 |
# Get database URL from environment or use SQLite as default
|
8 |
DATABASE_URL = os.getenv(
|
|
|
2 |
import os
|
3 |
from sqlalchemy import create_engine
|
4 |
from sqlalchemy.orm import sessionmaker
|
5 |
+
from app.models.database import Base
|
6 |
|
7 |
# Get database URL from environment or use SQLite as default
|
8 |
DATABASE_URL = os.getenv(
|
app/generator.py
CHANGED
@@ -8,7 +8,7 @@ import os
|
|
8 |
from huggingface_hub import hf_hub_download
|
9 |
from transformers import AutoTokenizer
|
10 |
from tokenizers.processors import TemplateProcessing
|
11 |
-
from app.
|
12 |
from app.text_normalizer import clean_text_for_tts
|
13 |
from app.text_normalizer import TextNormalizer
|
14 |
|
|
|
8 |
from huggingface_hub import hf_hub_download
|
9 |
from transformers import AutoTokenizer
|
10 |
from tokenizers.processors import TemplateProcessing
|
11 |
+
from app.model import Segment
|
12 |
from app.text_normalizer import clean_text_for_tts
|
13 |
from app.text_normalizer import TextNormalizer
|
14 |
|
app/main.py
CHANGED
@@ -18,7 +18,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
18 |
from fastapi.responses import RedirectResponse, FileResponse
|
19 |
from fastapi.staticfiles import StaticFiles
|
20 |
from app.api.routes import router as api_router
|
21 |
-
from app.
|
22 |
|
23 |
# Setup logging
|
24 |
os.makedirs("logs", exist_ok=True)
|
|
|
18 |
from fastapi.responses import RedirectResponse, FileResponse
|
19 |
from fastapi.staticfiles import StaticFiles
|
20 |
from app.api.routes import router as api_router
|
21 |
+
from app.models.database import Base, get_db
|
22 |
|
23 |
# Setup logging
|
24 |
os.makedirs("logs", exist_ok=True)
|
app/modelz/__init__.py
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
"""Models package initialization."""
|
2 |
-
from app.modelz.database import Base, Audiobook, AudiobookChunk, TextChunk, AudiobookStatus
|
3 |
-
|
4 |
-
__all__ = [
|
5 |
-
'Base',
|
6 |
-
'Audiobook',
|
7 |
-
'AudiobookChunk',
|
8 |
-
'TextChunk',
|
9 |
-
'AudiobookStatus'
|
10 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/modelz/database.py
DELETED
@@ -1,80 +0,0 @@
|
|
1 |
-
"""Database models and configuration."""
|
2 |
-
import os
|
3 |
-
from datetime import datetime
|
4 |
-
from enum import Enum
|
5 |
-
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime, ForeignKey, Enum as SQLEnum
|
6 |
-
from sqlalchemy.ext.declarative import declarative_base
|
7 |
-
from sqlalchemy.orm import sessionmaker, relationship
|
8 |
-
|
9 |
-
# Get database URL from environment or use SQLite as default
|
10 |
-
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///app/storage/audiobooks.db")
|
11 |
-
|
12 |
-
# Create engine
|
13 |
-
engine = create_engine(DATABASE_URL)
|
14 |
-
|
15 |
-
# Create session factory
|
16 |
-
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
17 |
-
|
18 |
-
# Create declarative base
|
19 |
-
Base = declarative_base()
|
20 |
-
|
21 |
-
class AudiobookStatus(str, Enum):
|
22 |
-
"""Status of an audiobook."""
|
23 |
-
PENDING = "pending"
|
24 |
-
PROCESSING = "processing"
|
25 |
-
COMPLETED = "completed"
|
26 |
-
FAILED = "failed"
|
27 |
-
|
28 |
-
class Audiobook(Base):
|
29 |
-
"""Audiobook model."""
|
30 |
-
__tablename__ = "audiobooks"
|
31 |
-
|
32 |
-
id = Column(String, primary_key=True)
|
33 |
-
title = Column(String, nullable=False)
|
34 |
-
author = Column(String, nullable=False)
|
35 |
-
voice_id = Column(String(50), nullable=False)
|
36 |
-
status = Column(SQLEnum(AudiobookStatus), nullable=False, default=AudiobookStatus.PENDING)
|
37 |
-
text_file_path = Column(String)
|
38 |
-
text_content = Column(Text)
|
39 |
-
audio_file_path = Column(String)
|
40 |
-
error_message = Column(Text)
|
41 |
-
created_at = Column(DateTime, default=datetime.utcnow)
|
42 |
-
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
43 |
-
|
44 |
-
# Relationships
|
45 |
-
chunks = relationship("AudiobookChunk", back_populates="audiobook")
|
46 |
-
|
47 |
-
class AudiobookChunk(Base):
|
48 |
-
"""Model for audiobook chunks for large books."""
|
49 |
-
__tablename__ = "audiobook_chunks"
|
50 |
-
|
51 |
-
id = Column(Integer, primary_key=True)
|
52 |
-
audiobook_id = Column(String, ForeignKey("audiobooks.id"))
|
53 |
-
chunk_number = Column(Integer, nullable=False)
|
54 |
-
text_content = Column(Text, nullable=False)
|
55 |
-
audio_file_path = Column(String)
|
56 |
-
status = Column(SQLEnum(AudiobookStatus), nullable=False, default=AudiobookStatus.PENDING)
|
57 |
-
created_at = Column(DateTime, default=datetime.utcnow)
|
58 |
-
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
59 |
-
|
60 |
-
# Relationships
|
61 |
-
audiobook = relationship("Audiobook", back_populates="chunks")
|
62 |
-
|
63 |
-
class TextChunk(Base):
|
64 |
-
"""Model for text chunks."""
|
65 |
-
__tablename__ = "text_chunks"
|
66 |
-
|
67 |
-
id = Column(Integer, primary_key=True)
|
68 |
-
audiobook_id = Column(String, ForeignKey("audiobooks.id"))
|
69 |
-
chunk_number = Column(Integer, nullable=False)
|
70 |
-
text_content = Column(Text, nullable=False)
|
71 |
-
created_at = Column(DateTime, default=datetime.utcnow)
|
72 |
-
|
73 |
-
# Dependency to get database session
|
74 |
-
def get_db():
|
75 |
-
"""Get database session."""
|
76 |
-
db = SessionLocal()
|
77 |
-
try:
|
78 |
-
yield db
|
79 |
-
finally:
|
80 |
-
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/voice_cloning.py
CHANGED
@@ -21,7 +21,7 @@ import torchaudio
|
|
21 |
from pydantic import BaseModel
|
22 |
from fastapi import UploadFile
|
23 |
|
24 |
-
from app.
|
25 |
|
26 |
# Set up logging
|
27 |
logger = logging.getLogger(__name__)
|
|
|
21 |
from pydantic import BaseModel
|
22 |
from fastapi import UploadFile
|
23 |
|
24 |
+
from app.model import Segment
|
25 |
|
26 |
# Set up logging
|
27 |
logger = logging.getLogger(__name__)
|
app/voice_enhancement.py
CHANGED
@@ -476,7 +476,7 @@ def get_voice_segments(voice_name: str, device: torch.device) -> List:
|
|
476 |
Returns:
|
477 |
List of context segments
|
478 |
"""
|
479 |
-
from app.
|
480 |
|
481 |
if voice_name not in VOICE_PROFILES:
|
482 |
logger.warning(f"Voice {voice_name} not found, defaulting to alloy")
|
|
|
476 |
Returns:
|
477 |
List of context segments
|
478 |
"""
|
479 |
+
from app.model import Segment
|
480 |
|
481 |
if voice_name not in VOICE_PROFILES:
|
482 |
logger.warning(f"Voice {voice_name} not found, defaulting to alloy")
|
app/voice_memory.py
CHANGED
@@ -7,7 +7,7 @@ import random
|
|
7 |
import logging
|
8 |
from typing import Dict, List, Optional
|
9 |
from dataclasses import dataclass
|
10 |
-
from app.
|
11 |
|
12 |
# Setup logging
|
13 |
logger = logging.getLogger(__name__)
|
|
|
7 |
import logging
|
8 |
from typing import Dict, List, Optional
|
9 |
from dataclasses import dataclass
|
10 |
+
from app.model import Segment
|
11 |
|
12 |
# Setup logging
|
13 |
logger = logging.getLogger(__name__)
|
scripts/migrate.py
CHANGED
@@ -21,13 +21,13 @@ logger = logging.getLogger(__name__)
|
|
21 |
logger.info(f"Current directory: {os.getcwd()}")
|
22 |
logger.info(f"Python Path (sys.path): {sys.path}")
|
23 |
|
24 |
-
models_db_path = "/app/app/
|
25 |
logger.info(f"Checking existence of {models_db_path}: {os.path.exists(models_db_path)}")
|
26 |
|
27 |
try:
|
28 |
# Direct import, assuming PYTHONPATH is correct
|
29 |
-
from app.
|
30 |
-
logger.info("Successfully imported Base from app.
|
31 |
except ImportError as e:
|
32 |
logger.error(f"Error importing Base: {e}")
|
33 |
# Log directory contents for deeper debugging
|
@@ -43,12 +43,12 @@ except ImportError as e:
|
|
43 |
logger.info(os.listdir("/app/app"))
|
44 |
except Exception as list_err:
|
45 |
logger.error(f"Could not list /app/app: {list_err}")
|
46 |
-
logger.info("Contents of /app/app/
|
47 |
-
if os.path.exists("/app/app/
|
48 |
try:
|
49 |
-
logger.info(os.listdir("/app/app/
|
50 |
except Exception as list_err:
|
51 |
-
logger.error(f"Could not list /app/app/
|
52 |
raise
|
53 |
|
54 |
def run_migrations():
|
|
|
21 |
logger.info(f"Current directory: {os.getcwd()}")
|
22 |
logger.info(f"Python Path (sys.path): {sys.path}")
|
23 |
|
24 |
+
models_db_path = "/app/app/models/database.py"
|
25 |
logger.info(f"Checking existence of {models_db_path}: {os.path.exists(models_db_path)}")
|
26 |
|
27 |
try:
|
28 |
# Direct import, assuming PYTHONPATH is correct
|
29 |
+
from app.models.database import Base
|
30 |
+
logger.info("Successfully imported Base from app.models.database")
|
31 |
except ImportError as e:
|
32 |
logger.error(f"Error importing Base: {e}")
|
33 |
# Log directory contents for deeper debugging
|
|
|
43 |
logger.info(os.listdir("/app/app"))
|
44 |
except Exception as list_err:
|
45 |
logger.error(f"Could not list /app/app: {list_err}")
|
46 |
+
logger.info("Contents of /app/app/models:")
|
47 |
+
if os.path.exists("/app/app/models"):
|
48 |
try:
|
49 |
+
logger.info(os.listdir("/app/app/models"))
|
50 |
except Exception as list_err:
|
51 |
+
logger.error(f"Could not list /app/app/models: {list_err}")
|
52 |
raise
|
53 |
|
54 |
def run_migrations():
|