Spaces:
Running
Running
Commit
·
321ea93
1
Parent(s):
d18dc62
Refactor imports across application files: update model import paths from 'app.models' to 'app.model' for consistency and clarity, ensuring correct module references throughout the codebase.
Browse files- Dockerfile +1 -1
- alembic/env.py +1 -1
- app/api/audiobook_routes.py +1 -1
- app/db.py +1 -1
- app/main.py +1 -1
- app/model/__init__.py +10 -0
- app/model/database.py +80 -0
- scripts/migrate.py +2 -2
Dockerfile
CHANGED
@@ -34,7 +34,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 && \
|
|
|
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/model:" && ls -la app/app/model
|
38 |
|
39 |
# Set up permissions
|
40 |
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.model.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.model.database import Audiobook, AudiobookStatus, AudiobookChunk, TextChunk
|
15 |
from app.services.storage import storage
|
16 |
from app.db import get_db
|
17 |
import torchaudio
|
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.model.database import Base
|
6 |
|
7 |
# Get database URL from environment or use SQLite as default
|
8 |
DATABASE_URL = os.getenv(
|
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.model.database import Base, get_db
|
22 |
|
23 |
# Setup logging
|
24 |
os.makedirs("logs", exist_ok=True)
|
app/model/__init__.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Models package initialization."""
|
2 |
+
from app.model.database import Base, Audiobook, AudiobookChunk, TextChunk, AudiobookStatus
|
3 |
+
|
4 |
+
__all__ = [
|
5 |
+
'Base',
|
6 |
+
'Audiobook',
|
7 |
+
'AudiobookChunk',
|
8 |
+
'TextChunk',
|
9 |
+
'AudiobookStatus'
|
10 |
+
]
|
app/model/database.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
scripts/migrate.py
CHANGED
@@ -26,8 +26,8 @@ logger.info(f"Checking existence of {models_db_path}: {os.path.exists(models_db_
|
|
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
|
|
|
26 |
|
27 |
try:
|
28 |
# Direct import, assuming PYTHONPATH is correct
|
29 |
+
from app.model.database import Base
|
30 |
+
logger.info("Successfully imported Base from app.model.database")
|
31 |
except ImportError as e:
|
32 |
logger.error(f"Error importing Base: {e}")
|
33 |
# Log directory contents for deeper debugging
|