File size: 2,817 Bytes
d520909
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
SPARKNET CLI Main Entry Point

Usage:
    sparknet document parse <file>
    sparknet document extract <file> --schema <schema.yaml>
    sparknet rag index <file>
    sparknet rag ask <question>
"""

import typer
from typing import Optional
from pathlib import Path
import json
import sys

from .document import document_app
from .rag import rag_app

# Create main app
app = typer.Typer(
    name="sparknet",
    help="SPARKNET Document Intelligence CLI",
    add_completion=False,
)

# Register sub-commands
app.add_typer(document_app, name="document", help="Document processing commands")
app.add_typer(rag_app, name="rag", help="RAG and retrieval commands")


@app.command()
def version():
    """Show SPARKNET version."""
    typer.echo("SPARKNET Document Intelligence v0.1.0")


@app.command()
def info():
    """Show system information and configuration."""
    from loguru import logger
    import platform

    typer.echo("SPARKNET Document Intelligence")
    typer.echo("=" * 40)
    typer.echo(f"Python: {platform.python_version()}")
    typer.echo(f"Platform: {platform.system()} {platform.release()}")
    typer.echo()

    # Check component availability
    typer.echo("Components:")

    # OCR
    try:
        from paddleocr import PaddleOCR
        typer.echo("  [βœ“] PaddleOCR")
    except ImportError:
        typer.echo("  [βœ—] PaddleOCR (install with: pip install paddleocr)")

    try:
        import pytesseract
        typer.echo("  [βœ“] Tesseract")
    except ImportError:
        typer.echo("  [βœ—] Tesseract (install with: pip install pytesseract)")

    # Vector Store
    try:
        import chromadb
        typer.echo("  [βœ“] ChromaDB")
    except ImportError:
        typer.echo("  [βœ—] ChromaDB (install with: pip install chromadb)")

    # Ollama
    try:
        import httpx
        with httpx.Client(timeout=2.0) as client:
            resp = client.get("http://localhost:11434/api/tags")
            if resp.status_code == 200:
                models = resp.json().get("models", [])
                typer.echo(f"  [βœ“] Ollama ({len(models)} models)")
            else:
                typer.echo("  [βœ—] Ollama (not responding)")
    except Exception:
        typer.echo("  [βœ—] Ollama (not running)")


@app.callback()
def main_callback(
    verbose: bool = typer.Option(False, "--verbose", "-v", help="Enable verbose output"),
    quiet: bool = typer.Option(False, "--quiet", "-q", help="Suppress output"),
):
    """SPARKNET Document Intelligence CLI."""
    from loguru import logger
    import sys

    # Configure logging
    logger.remove()
    if verbose:
        logger.add(sys.stderr, level="DEBUG")
    elif not quiet:
        logger.add(sys.stderr, level="INFO")


def main():
    """Main entry point."""
    app()


if __name__ == "__main__":
    main()