Spaces:
Sleeping
Sleeping
File size: 3,669 Bytes
e66f533 |
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 |
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
) |