525GradioApp / processors /classifier_processor.py
Ryan
update
e66f533
raw
history blame
3.67 kB
import gradio as gr
import logging
# Set up logging
logger = logging.getLogger('gradio_app.processors.classifier')
def process_classifier_analysis(analysis_results, prompt, analyses):
"""
Process Classifier analysis and return UI updates
Args:
analysis_results (dict): Complete analysis results
prompt (str): The prompt being analyzed
analyses (dict): Analysis data for the prompt
Returns:
tuple: UI component updates
"""
visualization_area_visible = True
classifier_results = analyses["classifier"]
models = classifier_results.get("models", [])
if len(models) < 2:
from analysis_runner import default_no_visualization
return default_no_visualization(analysis_results)
prompt_title_visible = True
prompt_title_value = f"## Analysis of Prompt: \"{prompt[:100]}...\""
models_compared_visible = True
models_compared_value = f"### Classifier Analysis for {models[0]} and {models[1]}"
# Extract and format classifier information
model1_name = models[0]
model2_name = models[1]
# Display classifications for each model
classifications = classifier_results.get("classifications", {})
model1_title_visible = False
model1_title_value = ""
model1_words_visible = False
model1_words_value = ""
if classifications:
model1_title_visible = True
model1_title_value = f"#### Classification Results"
model1_words_visible = True
model1_results = classifications.get(model1_name, {})
model2_results = classifications.get(model2_name, {})
model1_words_value = f"""
**{model1_name}**:
- Formality: {model1_results.get('formality', 'N/A')}
- Sentiment: {model1_results.get('sentiment', 'N/A')}
- Complexity: {model1_results.get('complexity', 'N/A')}
**{model2_name}**:
- Formality: {model2_results.get('formality', 'N/A')}
- Sentiment: {model2_results.get('sentiment', 'N/A')}
- Complexity: {model2_results.get('complexity', 'N/A')}
"""
# Show comparison
model2_title_visible = False
model2_title_value = ""
model2_words_visible = False
model2_words_value = ""
differences = classifier_results.get("differences", {})
if differences:
model2_title_visible = True
model2_title_value = f"#### Classification Comparison"
model2_words_visible = True
model2_words_value = "\n".join([
f"- **{category}**: {diff}"
for category, diff in differences.items()
])
return (
analysis_results, # analysis_results_state
False, # analysis_output visibility
True, # visualization_area_visible
gr.update(visible=True), # analysis_title
gr.update(visible=prompt_title_visible, value=prompt_title_value), # prompt_title
gr.update(visible=models_compared_visible, value=models_compared_value), # models_compared
gr.update(visible=model1_title_visible, value=model1_title_value), # model1_title
gr.update(visible=model1_words_visible, value=model1_words_value), # model1_words
gr.update(visible=model2_title_visible, value=model2_title_value), # model2_title
gr.update(visible=model2_words_visible, value=model2_words_value), # model2_words
gr.update(visible=False), # similarity_metrics_title
gr.update(visible=False), # similarity_metrics
False, # status_message_visible
gr.update(visible=False), # status_message
gr.update(visible=False) # bias_visualizations - Not visible for Classifier analysis
)