File size: 3,339 Bytes
e66f533
 
 
 
 
 
 
 
 
 
 
 
 
 
11b02dc
e66f533
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eabf2c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import logging

# Set up logging
logger = logging.getLogger('gradio_app.visualization_handler')


def create_visualization_components():
    """
    Creates all the visualization components used in the analysis tab

    Returns:
        list: A list of all gradio components for visualization
    """
    bias_visualizations = gr.Markdown(visible=False)
    # Pre-create visualization components (initially hidden)
    visualization_area_visible = gr.Checkbox(value=False, visible=False, label="Visualization Visible")
    analysis_title = gr.Markdown("## Analysis Results", visible=False)
    prompt_title = gr.Markdown(visible=False)
    models_compared = gr.Markdown(visible=False)

    # Container for model 1 words
    model1_title = gr.Markdown(visible=False)
    model1_words = gr.Markdown(visible=False)

    # Container for model 2 words
    model2_title = gr.Markdown(visible=False)
    model2_words = gr.Markdown(visible=False)

    # Similarity metrics
    similarity_metrics_title = gr.Markdown("### Similarity Metrics", visible=False)
    similarity_metrics = gr.Markdown(visible=False)

    # Status or error message area
    status_message_visible = gr.Checkbox(value=False, visible=False, label="Status Message Visible")
    status_message = gr.Markdown(visible=False)

    # Create bias visualization container (initially hidden)
    with gr.Column(visible=False) as bias_visualizations:
        gr.Markdown("### Bias Analysis Visualizations")
        # This will be populated dynamically

    # Return all components as a list
    return [
        analysis_results_state := gr.State({}),
        analysis_output := gr.JSON(visible=False),
        visualization_area_visible,
        analysis_title,
        prompt_title,
        models_compared,
        model1_title,
        model1_words,
        model2_title,
        model2_words,
        similarity_metrics_title,
        similarity_metrics,
        status_message_visible,
        status_message,
        bias_visualizations
    ]


def process_and_visualize_bias_analysis(analysis_results):
    """
    Wrapper for bias visualization function from visualization.bias_visualizer

    Args:
        analysis_results (dict): The analysis results

    Returns:
        list: Components for bias visualization
    """
    from visualization.bias_visualizer import process_and_visualize_bias_analysis
    return process_and_visualize_bias_analysis(analysis_results)


def process_and_visualize_ngram_analysis(analysis_results):
    """
    Wrapper for n-gram visualization function from visualization.ngram_visualizer

    Args:
        analysis_results (dict): The analysis results

    Returns:
        list: Components for n-gram visualization
    """
    from visualization.ngram_visualizer import process_and_visualize_ngram_analysis
    return process_and_visualize_ngram_analysis(analysis_results)


def process_and_visualize_topic_analysis(analysis_results):
    """
    Wrapper for topic modeling visualization function from visualization.topic_visualizer

    Args:
        analysis_results (dict): The analysis results

    Returns:
        list: Components for topic visualization
    """
    from visualization.topic_visualizer import process_and_visualize_topic_analysis
    return process_and_visualize_topic_analysis(analysis_results)