Add comprehensive documentation and code comments
This commit adds extensive documentation to the Mistral OCR CLI project: - Add API.md with detailed API response format documentation - Add CHANGELOG.md to track version changes - Add CONTRIBUTING.md with guidelines for contributors - Enhance README.md with more detailed usage examples and troubleshooting - Add proper docstrings to all Python modules and functions - Update requirements.txt with development dependencies - Improve setup.py with better metadata These changes make the project more accessible to users and contributors.
This commit is contained in:
@@ -6,6 +6,14 @@ import urllib.parse
|
||||
from mistral_ocr.client import MistralClient
|
||||
|
||||
def run(args):
|
||||
"""
|
||||
Main entry point for the process command.
|
||||
|
||||
Processes a document with OCR, either from a URL or a local file.
|
||||
|
||||
Args:
|
||||
args: Command line arguments parsed by argparse
|
||||
"""
|
||||
file_path = args.file
|
||||
|
||||
# Determine if input is a URL or a local file
|
||||
@@ -15,6 +23,17 @@ def run(args):
|
||||
process_local_file(file_path, args.output_file, args.include_images)
|
||||
|
||||
def process_url(url, output_file, include_image_base64):
|
||||
"""
|
||||
Process a document from a URL.
|
||||
|
||||
Args:
|
||||
url (str): URL of the document to process
|
||||
output_file (str): Path to save the OCR results, or None for stdout
|
||||
include_image_base64 (bool): Whether to include base64-encoded images in the output
|
||||
|
||||
Raises:
|
||||
SystemExit: If an error occurs during processing
|
||||
"""
|
||||
try:
|
||||
client = MistralClient()
|
||||
|
||||
@@ -35,6 +54,17 @@ def process_url(url, output_file, include_image_base64):
|
||||
sys.exit(1)
|
||||
|
||||
def process_local_file(file_path, output_file, include_image_base64):
|
||||
"""
|
||||
Process a local document file.
|
||||
|
||||
Args:
|
||||
file_path (str): Path to the local file to process
|
||||
output_file (str): Path to save the OCR results, or None for stdout
|
||||
include_image_base64 (bool): Whether to include base64-encoded images in the output
|
||||
|
||||
Raises:
|
||||
SystemExit: If an error occurs during processing
|
||||
"""
|
||||
try:
|
||||
print(f"Processing local file: {file_path}")
|
||||
|
||||
@@ -71,6 +101,13 @@ def process_local_file(file_path, output_file, include_image_base64):
|
||||
sys.exit(1)
|
||||
|
||||
def handle_output(data, output_file):
|
||||
"""
|
||||
Handle the OCR response output.
|
||||
|
||||
Args:
|
||||
data (bytes): JSON response data from the OCR API
|
||||
output_file (str): Path to save the OCR results, or None for stdout
|
||||
"""
|
||||
# Pretty print the JSON response
|
||||
pretty_json = json.dumps(json.loads(data), indent=2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user