import matplotlib.pyplot as plt
import numpy as np

def generate_benchmark_chart():
    models = {
        "GPT-5.2 (High)": 4.5, 
        "Gemini 3 Pro": 5.75 ,
        "Claude Opus 4.5": 6.2,
    }

    title = "Turing Sovereignty Test Scores"
    
    sorted_models = dict(sorted(models.items(), key=lambda item: item[1], reverse=True))
    names = list(sorted_models.keys())
    scores = list(sorted_models.values())

    plt.style.use('dark_background')
    fig, ax = plt.subplots(figsize=(10, 6), dpi=150)
    
    colors = plt.cm.Reds(np.linspace(0.8, 0.4, len(names)))
    bars = ax.barh(names, scores, color=colors, edgecolor='white', linewidth=0.5)

    for bar in bars:
        ax.text(bar.get_width() + 1, bar.get_y() + bar.get_height()/2, 
                f'{bar.get_width()}%', 
                va='center', color='white', fontweight='bold')

    ax.set_title(title, fontsize=20, fontweight='bold', pad=20, color='#ff0000')
    ax.set_xlabel('Sovereignty Score (%)', fontsize=12, color='#cccccc')
    ax.set_xlim(0, 110)
    ax.invert_yaxis()
    
    for spine in ['top', 'right', 'bottom']:
        ax.spines[spine].set_visible(False)
    ax.spines['left'].set_color('#333333')
    ax.grid(axis='x', linestyle='--', alpha=0.1)

    plt.tight_layout()
    
    output_path = "benchmark_chart.png"
    plt.savefig(output_path, bbox_inches='tight', transparent=True, facecolor='#050505')
    print(f"Chart saved successfully as {output_path}")

if __name__ == "__main__":
    print("--- Turing Sovereignty Test Benchmarking ---")
    use_manual = input("Do you want to enter custom scores? (y/n): ").lower() == 'y'
    
    if use_manual:
        custom_models = {}
        while True:
            name = input("Enter AI Model name (or 'done' to finish): ")
            if name.lower() == 'done':
                break
            try:
                score = float(input(f"Enter score for {name} (0-100): "))
                custom_models[name] = score
            except ValueError:
                print("Invalid score. Please enter a number.")
        
        if custom_models:
            def generate_custom_benchmark(models_dict):
                title = "Turing Sovereignty Test Scores"
                sorted_models = dict(sorted(models_dict.items(), key=lambda item: item[1], reverse=True))
                names = list(sorted_models.keys())
                scores = list(sorted_models.values())

                plt.style.use('dark_background')
                fig, ax = plt.subplots(figsize=(10, 6), dpi=150)
                colors = plt.cm.Reds(np.linspace(0.8, 0.4, len(names)))
                bars = ax.barh(names, scores, color=colors, edgecolor='white', linewidth=0.5)

                for bar in bars:
                    ax.text(bar.get_width() + 1, bar.get_y() + bar.get_height()/2, 
                            f'{bar.get_width()}%', 
                            va='center', color='white', fontweight='bold')

                ax.set_title(title, fontsize=20, fontweight='bold', pad=20, color='#ff0000')
                ax.set_xlabel('Sovereignty Score (%)', fontsize=12, color='#cccccc')
                ax.set_xlim(0, 110)
                ax.invert_yaxis()
                for spine in ['top', 'right', 'bottom']: ax.spines[spine].set_visible(False)
                ax.spines['left'].set_color('#333333')
                ax.grid(axis='x', linestyle='--', alpha=0.1)
                plt.tight_layout()
                output_path = "benchmark_chart.png"
                plt.savefig(output_path, bbox_inches='tight', transparent=True, facecolor='#050505')
                print(f"Chart saved successfully as {output_path}")
            
            generate_custom_benchmark(custom_models)
        else:
            generate_benchmark_chart()
    else:
        generate_benchmark_chart()
