Update app.py
Browse files
app.py
CHANGED
@@ -484,7 +484,6 @@ class SentimentEngine:
|
|
484 |
|
485 |
return results
|
486 |
|
487 |
-
# FIXED Advanced Analysis Engine
|
488 |
class AdvancedAnalysisEngine:
|
489 |
"""Advanced analysis using SHAP and LIME with FIXED implementation"""
|
490 |
|
@@ -627,14 +626,14 @@ class AdvancedAnalysisEngine:
|
|
627 |
}
|
628 |
|
629 |
summary_text = f"""
|
630 |
-
**SHAP Analysis Results
|
631 |
- **Language:** {detected_lang.upper()}
|
632 |
- **Total Tokens:** {analysis_data['total_tokens']}
|
633 |
- **Samples Used:** {num_samples}
|
634 |
- **Positive Influence Tokens:** {analysis_data['positive_influence']}
|
635 |
- **Negative Influence Tokens:** {analysis_data['negative_influence']}
|
636 |
- **Most Important Tokens:** {', '.join([f"{token}({score:.3f})" for token, score in analysis_data['most_important_tokens']])}
|
637 |
-
- **Status:**
|
638 |
"""
|
639 |
|
640 |
return summary_text, fig, analysis_data
|
@@ -739,7 +738,7 @@ class AdvancedAnalysisEngine:
|
|
739 |
}
|
740 |
|
741 |
summary_text = f"""
|
742 |
-
**LIME Analysis Results
|
743 |
- **Language:** {detected_lang.upper()}
|
744 |
- **Features Analyzed:** {analysis_data['features_analyzed']}
|
745 |
- **Classes:** {', '.join(class_names)}
|
@@ -747,7 +746,7 @@ class AdvancedAnalysisEngine:
|
|
747 |
- **Positive Features:** {analysis_data['positive_features']}
|
748 |
- **Negative Features:** {analysis_data['negative_features']}
|
749 |
- **Top Features:** {', '.join([f"{word}({score:.3f})" for word, score in lime_data[:5]])}
|
750 |
-
- **Status:**
|
751 |
"""
|
752 |
|
753 |
return summary_text, fig, analysis_data
|
@@ -1033,7 +1032,7 @@ class DataHandler:
|
|
1033 |
|
1034 |
return content
|
1035 |
|
1036 |
-
|
1037 |
class SentimentApp:
|
1038 |
"""Optimized multilingual sentiment analysis application"""
|
1039 |
|
@@ -1272,8 +1271,8 @@ def create_interface():
|
|
1272 |
app = SentimentApp()
|
1273 |
|
1274 |
with gr.Blocks(theme=gr.themes.Soft(), title="Multilingual Sentiment Analyzer") as demo:
|
1275 |
-
gr.Markdown("# π
|
1276 |
-
gr.Markdown("AI-powered sentiment analysis with
|
1277 |
|
1278 |
with gr.Tab("Single Analysis"):
|
1279 |
with gr.Row():
|
@@ -1317,8 +1316,8 @@ def create_interface():
|
|
1317 |
probability_plot = gr.Plot(label="Probability Distribution")
|
1318 |
|
1319 |
# FIXED Advanced Analysis Tab
|
1320 |
-
with gr.Tab("π¬ Advanced Analysis
|
1321 |
-
gr.Markdown("##
|
1322 |
gr.Markdown("**SHAP and LIME analysis with FIXED implementation** - now handles text input correctly!")
|
1323 |
|
1324 |
with gr.Row():
|
@@ -1351,12 +1350,6 @@ def create_interface():
|
|
1351 |
lime_btn = gr.Button("β
LIME Analysis (FIXED)", variant="secondary")
|
1352 |
|
1353 |
gr.Markdown("""
|
1354 |
-
**π οΈ FIXES Applied:**
|
1355 |
-
- β
**Text Input Format**: Fixed string/array handling for SHAP
|
1356 |
-
- β
**Prediction Function**: Robust batch processing with error handling
|
1357 |
-
- β
**Token Extraction**: Safe data extraction with length matching
|
1358 |
-
- β
**Model Compatibility**: Works with 2-class and 3-class models
|
1359 |
-
- β
**Error Recovery**: Graceful fallback for failed predictions
|
1360 |
|
1361 |
**π Analysis Methods:**
|
1362 |
- **SHAP**: Token-level importance scores using Text masker
|
|
|
484 |
|
485 |
return results
|
486 |
|
|
|
487 |
class AdvancedAnalysisEngine:
|
488 |
"""Advanced analysis using SHAP and LIME with FIXED implementation"""
|
489 |
|
|
|
626 |
}
|
627 |
|
628 |
summary_text = f"""
|
629 |
+
**SHAP Analysis Results:**
|
630 |
- **Language:** {detected_lang.upper()}
|
631 |
- **Total Tokens:** {analysis_data['total_tokens']}
|
632 |
- **Samples Used:** {num_samples}
|
633 |
- **Positive Influence Tokens:** {analysis_data['positive_influence']}
|
634 |
- **Negative Influence Tokens:** {analysis_data['negative_influence']}
|
635 |
- **Most Important Tokens:** {', '.join([f"{token}({score:.3f})" for token, score in analysis_data['most_important_tokens']])}
|
636 |
+
- **Status:** SHAP analysis completed successfully
|
637 |
"""
|
638 |
|
639 |
return summary_text, fig, analysis_data
|
|
|
738 |
}
|
739 |
|
740 |
summary_text = f"""
|
741 |
+
**LIME Analysis Results:**
|
742 |
- **Language:** {detected_lang.upper()}
|
743 |
- **Features Analyzed:** {analysis_data['features_analyzed']}
|
744 |
- **Classes:** {', '.join(class_names)}
|
|
|
746 |
- **Positive Features:** {analysis_data['positive_features']}
|
747 |
- **Negative Features:** {analysis_data['negative_features']}
|
748 |
- **Top Features:** {', '.join([f"{word}({score:.3f})" for word, score in lime_data[:5]])}
|
749 |
+
- **Status:** LIME analysis completed successfully
|
750 |
"""
|
751 |
|
752 |
return summary_text, fig, analysis_data
|
|
|
1032 |
|
1033 |
return content
|
1034 |
|
1035 |
+
|
1036 |
class SentimentApp:
|
1037 |
"""Optimized multilingual sentiment analysis application"""
|
1038 |
|
|
|
1271 |
app = SentimentApp()
|
1272 |
|
1273 |
with gr.Blocks(theme=gr.themes.Soft(), title="Multilingual Sentiment Analyzer") as demo:
|
1274 |
+
gr.Markdown("# π Multilingual Sentiment Analyzer")
|
1275 |
+
gr.Markdown("AI-powered sentiment analysis with SHAP & LIME explainable AI features")
|
1276 |
|
1277 |
with gr.Tab("Single Analysis"):
|
1278 |
with gr.Row():
|
|
|
1316 |
probability_plot = gr.Plot(label="Probability Distribution")
|
1317 |
|
1318 |
# FIXED Advanced Analysis Tab
|
1319 |
+
with gr.Tab("π¬ Advanced Analysis"):
|
1320 |
+
gr.Markdown("## Explainable AI Analysis")
|
1321 |
gr.Markdown("**SHAP and LIME analysis with FIXED implementation** - now handles text input correctly!")
|
1322 |
|
1323 |
with gr.Row():
|
|
|
1350 |
lime_btn = gr.Button("β
LIME Analysis (FIXED)", variant="secondary")
|
1351 |
|
1352 |
gr.Markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
1353 |
|
1354 |
**π Analysis Methods:**
|
1355 |
- **SHAP**: Token-level importance scores using Text masker
|