Technical Details¶
API Specifications¶
1. GPT Generate Book TOC with Prompts (http://127.0.0.1:7998/gpt_generate_book_toc_with_prompts)¶
Request Format¶
Parameters¶
- context (string): Instructional context for content generation (e.g., "fac un curs pentru elevi postliceala medicina")
- what_to_build (string): Detailed curriculum content to be processed and structured
- language (string): Target language for output. Default is "english", must be set to "romana" for Romanian content
Response Format¶
- link (string): Direct URL to the generated TOC file
TOC File Format¶
The generated TOC follows a specific hierarchical structure:
[Section Number] [Section Title] #!# [Detailed Content Prompt]
[Subsection Number] [Subsection Title] #!# [Detailed Content Prompt]
...
Example:
1. Tehnici de nursing – partea II: Alimentația bolnavului #!# Generați un conținut detaliat...
1.1 Tipuri de alimentare #!# Oferiți o descriere detaliată...
$%%$ [filename-slug]
$^^$ [Document description]
2. GPT TOC to PDF (http://127.0.0.1:7998/gpt_toc_to_pdf)¶
Request Format¶
Parameters¶
- link (string): URL to the TOC file generated by the first API
Response Format¶
- link (string): Direct URL to the generated PDF file
Data Formats and Processing¶
OCR Input Formats¶
- Supported File Types: PDF, JPEG, PNG, TIFF
- Encoding: UTF-8 preferred
- Image Requirements: Minimum resolution 300 DPI for optimal OCR accuracy
OCR Processing Steps¶
- Image Extraction (for PDFs): Convert pages to individual images
- Rotation Correction: Automatically detect and correct crooked/rotated images using computer vision algorithms
- Text Recognition: Tesseract OCR with Romanian language training data
- Text Cleaning: Remove artifacts, normalize whitespace, fix common OCR errors
- Structure Recognition: Preserve tabular structure and hierarchy indicators
LLM Processing Input Preparation¶
- Concatenation: Raw OCR text appened directly to context prompts
- Length Handling: Process large documents in chunks if necessary
- Content Validation: Ensure minimum content length for meaningful structure generation
File Management¶
Directory Structure¶
/app/
├── main.py (Streamlit app)
├── requirements.txt
├── outputs/
│ ├── generated_001.pdf
│ ├── generated_002.pdf
│ └── ...
└── temp/
├── upload_001.pdf
├── ocr_001.txt
└── ...
File Naming Convention¶
- Input Files:
upload_{timestamp}_{original_name} - OCR Output:
ocr_{timestamp}.txt - Generated PDFs:
course_{timestamp}.pdf - Temporary Files: Automatic cleanup after processing
Storage Limits¶
- Max File Size: 50MB per input document
- Output Retention: 30 days automatic cleanup
- Concurrent Processing: Maximum 3 simultaneous uploads
Error Handling¶
Common Error Scenarios¶
- OCR Failure: Low-quality scans, unsupported formats
- API Timeout: Network issues, server overload
- Invalid TOC: Malformed links, corrupted files
- Storage Full: Disk space exhaustion
Error Response Codes¶
400 Bad Request: Invalid input parameters408 Request Timeout: API call timeout500 Internal Server Error: Processing failure
Recovery Mechanisms¶
- Retry Logic: Exponential backoff for API calls (max 3 retries)
- Fallback Options: Manual text input when OCR fails
- User Feedback: Clear error messages and suggested actions
Performance Metrics¶
Expected Processing Times¶
- OCR Only: 30-60 seconds per page
- TOC Generation: 2-5 minutes depending on content complexity
- PDF Generation: 1-3 minutes based on TOC size
- Total Workflow: 5-10 minutes for typical curriculum
Resource Usage¶
- Memory: 2-4GB peak during PDF generation
- CPU: High during OCR processing
- Network: API calls require stable internet connection
Security Considerations¶
Data Handling¶
- File Sanitization: Input validation and malware scanning
- Temporary File Cleanup: Automatic deletion of processing artifacts
- URL Validation: Only accept specific domain patterns for API links
Privacy Protection¶
- No Data Persistence: Documents processed in memory when possible
- Cleanup Policies: Automatic deletion of temporary files
- Audit Logging: Processing history without storing content
Integration Points¶
External Dependencies¶
- Tesseract OCR: Local installation required
- Streamlit: Web server running on default port
- LLM API: Remote service on localhost:7998
Configuration Requirements¶
- Environment Variables: API endpoints, timeouts, file paths
- System Dependencies: Tesseract, Streamlit, Python packages
- Network Access: API server accessibility
Debugging and Monitoring¶
Logging Levels¶
- INFO: Processing progress and API responses
- WARNING: Recoverable errors and fallback actions
- ERROR: Critical failures requiring intervention
Monitoring Points¶
- OCR success rate
- API response times
- File processing success rate
- User download completions