525GradioApp / visualization_handler.py
Ryan
update
eabf2c4
raw
history blame
3.34 kB
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)