Implementation:869413421 Ai moive studio ProjectProcessingService process uploaded file
| Knowledge Sources | |
|---|---|
| Domains | Preprocessing, NLP |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Service that orchestrates the complete file processing workflow: cleaning existing data, parsing text content, saving the chapter/paragraph/sentence hierarchy, and updating project status.
Description
ProjectProcessingService.process_uploaded_file is the entry point for processing an uploaded file in the Picture Narrative Pipeline. It coordinates multiple services to: (1) fetch the project record, (2) clean any existing parsed data, (3) update project status to PARSING, (4) parse text via TextParserService, (5) batch-save the three-level hierarchy (Chapter→Paragraph→Sentence) to the database, (6) update project statistics, and (7) mark the project as PARSED.
The entire operation runs within a transaction with automatic rollback on failure.
Usage
Import this service when you need to process an uploaded text file and build the chapter/paragraph/sentence hierarchy for a project. Called by Celery tasks after file upload and encoding detection.
Code Reference
Source Location
- Repository: ai-moive-studio
- File: backend/src/services/project_processing.py:L77-151
Signature
class ProjectProcessingService(BaseService):
async def process_uploaded_file(self, project_id: str, file_content: str) -> Dict:
"""
Args:
project_id: UUID of the project
file_content: UTF-8 text content extracted from uploaded file
Returns:
Dict with success, project_id, chapters_count, paragraphs_count,
sentences_count, message
"""
Import
from src.services.project_processing import ProjectProcessingService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| project_id | str | Yes | UUID of the project to process |
| file_content | str | Yes | UTF-8 text content from the uploaded file |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | Dict | {success, project_id, chapters_count, paragraphs_count, sentences_count, message} |
| DB side effects | — | Persists Chapter, Paragraph, Sentence records; updates Project status to 'parsed' |
Usage Examples
Processing an Uploaded File
from src.services.project_processing import ProjectProcessingService
from src.core.database import get_async_db
async def handle_upload(project_id: str, file_content: str):
async with get_async_db() as session:
service = ProjectProcessingService(session)
result = await service.process_uploaded_file(
project_id=project_id,
file_content=file_content,
)
print(f"Parsed: {result['chapters_count']} chapters, "
f"{result['sentences_count']} sentences")