File size: 2,328 Bytes
405a3f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import os
import logging

# Add the base directory to the Python path to make local package imports work cleanly
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from src.inference import get_or_load_resources, predict_review, generate_explanation

# Configure minimal CLI logging
logging.basicConfig(level=logging.WARNING, format='%(asctime)s [%(levelname)s] %(message)s')

if __name__ == "__main__":
    print("=" * 70)
    print("SentinelReview AI - Review Authenticity Terminal Audit Utility")
    print("=" * 70)
    
    try:
        # Pre-warm resources
        print("\n[CLI Status] Loading local weights and preprocessors...")
        get_or_load_resources()
        print("[CLI Status] Initialization complete.\n")
        
        # User input text prompt
        print("Please enter the review text to analyze:")
        review_text = sys.stdin.read().strip()
        
        if not review_text:
            print("\n[CLI Error] Input review text cannot be empty.")
            sys.exit(1)
            
        print("\n" + "-" * 50)
        print("[CLI Audit] Executing multi-vector audit analysis...")
        print("-" * 50)
        
        # Perform prediction
        results = predict_review(review_text)
        
        # Fetch explanation
        explanation = generate_explanation(review_text, results['classification'])
        
        # Render clean, professional report
        print(f"\nAUDIT STATUS      : {results['classification'].upper()}")
        print(f"CONFIDENCE LEVEL  : {int(results['confidence'] * 100)}%")
        print(f"SENTIMENT METRIC  : {results['metrics']['sentiment_score']} (VADER compound)")
        print(f"CHARACTER LENGTH  : {results['metrics']['length']}")
        print(f"WORD COUNT        : {results['metrics']['words_count']}")
        print(f"CAPITAL RATIO     : {int(results['metrics']['capitalization_ratio'] * 100)}%")
        print(f"PUNCTUATION COUNT : {results['metrics']['punctuation_count']}")
        
        print("\nEXPLANATION ANALYSIS:")
        print(explanation)
        print("\n" + "=" * 70)
        
    except KeyboardInterrupt:
        print("\n[CLI Status] Execution interrupted by developer.")
        sys.exit(0)
    except Exception as e:
        print(f"\n[CLI Error] Critical execution crash: {e}")
        sys.exit(1)