Krish Patel commited on
Commit
21bc2b4
Β·
1 Parent(s): 15e4be7
Files changed (1) hide show
  1. app.py +47 -76
app.py CHANGED
@@ -144,6 +144,9 @@ def main():
144
  gemini_result = analyze_content_gemini(gemini_model, news_text)
145
 
146
  # First show the high-level metrics in columns
 
 
 
147
  col1, col2, col3 = st.columns(3)
148
 
149
  with col1:
@@ -163,83 +166,51 @@ def main():
163
  st.metric("Prediction", gemini_pred)
164
  st.metric("Confidence", f"{gemini_conf}%")
165
 
166
- # Single expander for all detailed analysis
167
- with st.expander("View All Analysis Details"):
168
- # Named Entities Section
169
- st.subheader("🏷️ Named Entities")
170
- entities = extract_entities(news_text, nlp)
171
- df = pd.DataFrame(entities, columns=["Entity", "Type"])
172
- st.dataframe(df)
173
-
174
- # Knowledge Graph Section
175
- st.subheader("πŸ•ΈοΈ Knowledge Graph")
176
- fig = generate_knowledge_graph_viz(news_text, nlp, tokenizer, model)
177
- st.plotly_chart(fig, use_container_width=True)
178
-
179
- # Detailed Gemini Analysis
180
- st.subheader("πŸ“ Text Classification")
181
- text_class = gemini_result.get('text_classification', {})
182
- st.write(f"Category: {text_class.get('category', 'N/A')}")
183
-
184
- # Detailed analysis sections
185
- with st.expander("View Detailed Analysis"):
186
- with st.expander("View Detailed Analysis"):
187
- try:
188
- # Text Classification
189
- st.subheader("πŸ“ Text Classification")
190
- text_class = gemini_result.get('text_classification', {})
191
- st.write(f"Category: {text_class.get('category', 'N/A')}")
192
- st.write(f"Writing Style: {text_class.get('writing_style', 'N/A')}")
193
- st.write(f"Target Audience: {text_class.get('target_audience', 'N/A')}")
194
- st.write(f"Content Type: {text_class.get('content_type', 'N/A')}")
195
-
196
- # Sentiment Analysis
197
- st.subheader("🎭 Sentiment Analysis")
198
- sentiment = gemini_result.get('sentiment_analysis', {})
199
- st.write(f"Primary Emotion: {sentiment.get('primary_emotion', 'N/A')}")
200
- st.write(f"Emotional Intensity: {sentiment.get('emotional_intensity', 'N/A')}/10")
201
- st.write(f"Sensationalism Level: {sentiment.get('sensationalism_level', 'N/A')}")
202
- st.write("Bias Indicators:", ", ".join(sentiment.get('bias_indicators', ['N/A'])))
 
 
 
 
203
 
204
- tone = sentiment.get('tone', {})
205
- st.write(f"Tone Formality: {tone.get('formality', 'N/A')}")
206
- st.write(f"Tone Style: {tone.get('style', 'N/A')}")
207
- st.write("Emotional Triggers:", ", ".join(sentiment.get('emotional_triggers', ['N/A'])))
208
-
209
- # Entity Recognition
210
- st.subheader("πŸ” Entity Recognition")
211
- entities = gemini_result.get('entity_recognition', {})
212
- st.write(f"Source Credibility: {entities.get('source_credibility', 'N/A')}")
213
- st.write("People:", ", ".join(entities.get('people', ['N/A'])))
214
- st.write("Organizations:", ", ".join(entities.get('organizations', ['N/A'])))
215
- st.write("Locations:", ", ".join(entities.get('locations', ['N/A'])))
216
- st.write("Dates:", ", ".join(entities.get('dates', ['N/A'])))
217
- st.write("Statistics:", ", ".join(entities.get('statistics', ['N/A'])))
218
-
219
- # Context
220
- st.subheader("πŸ“° Context")
221
- context = gemini_result.get('context', {})
222
- st.write("Main Narrative:", context.get('main_narrative', 'N/A'))
223
- st.write("Supporting Elements:", ", ".join(context.get('supporting_elements', ['N/A'])))
224
- st.write("Key Claims:", ", ".join(context.get('key_claims', ['N/A'])))
225
- st.write("Narrative Structure:", context.get('narrative_structure', 'N/A'))
226
-
227
- # Fact Checking
228
- st.subheader("βœ”οΈ Fact Checking")
229
- fact_check = gemini_result.get('fact_checking', {})
230
- st.write("Verifiable Claims:")
231
- for claim in fact_check.get('verifiable_claims', ['N/A']):
232
- st.write(f"β€’ {claim}")
233
- st.write(f"Evidence Present: {fact_check.get('evidence_present', 'N/A')}")
234
- st.write(f"Fact Check Score: {fact_check.get('fact_check_score', 'N/A')}/100")
235
-
236
- # Analysis Reasoning
237
- st.subheader("πŸ’­ Analysis Reasoning")
238
- for point in gemini_result.get('gemini_analysis', {}).get('reasoning', ['N/A']):
239
- st.write(f"β€’ {point}")
240
-
241
- except Exception as e:
242
- st.error("Error processing Gemini analysis results")
243
 
244
 
245
  with st.expander("Named Entities"):
 
144
  gemini_result = analyze_content_gemini(gemini_model, news_text)
145
 
146
  # First show the high-level metrics in columns
147
+ # In the main() function:
148
+
149
+ # Display metrics in columns
150
  col1, col2, col3 = st.columns(3)
151
 
152
  with col1:
 
166
  st.metric("Prediction", gemini_pred)
167
  st.metric("Confidence", f"{gemini_conf}%")
168
 
169
+ # Single expander for all analysis details
170
+ with st.expander("Detailed Analysis"):
171
+ try:
172
+ # Text Classification
173
+ st.subheader("πŸ“ Text Classification")
174
+ text_class = gemini_result.get('text_classification', {})
175
+ st.write(f"Category: {text_class.get('category', 'N/A')}")
176
+ st.write(f"Writing Style: {text_class.get('writing_style', 'N/A')}")
177
+ st.write(f"Target Audience: {text_class.get('target_audience', 'N/A')}")
178
+ st.write(f"Content Type: {text_class.get('content_type', 'N/A')}")
179
+
180
+ # Sentiment Analysis
181
+ st.subheader("🎭 Sentiment Analysis")
182
+ sentiment = gemini_result.get('sentiment_analysis', {})
183
+ st.write(f"Primary Emotion: {sentiment.get('primary_emotion', 'N/A')}")
184
+ st.write(f"Emotional Intensity: {sentiment.get('emotional_intensity', 'N/A')}/10")
185
+ st.write(f"Sensationalism Level: {sentiment.get('sensationalism_level', 'N/A')}")
186
+ st.write("Bias Indicators:", ", ".join(sentiment.get('bias_indicators', ['N/A'])))
187
+
188
+ # Entity Recognition
189
+ st.subheader("πŸ” Entity Recognition")
190
+ entities = gemini_result.get('entity_recognition', {})
191
+ st.write(f"Source Credibility: {entities.get('source_credibility', 'N/A')}")
192
+ st.write("People:", ", ".join(entities.get('people', ['N/A'])))
193
+ st.write("Organizations:", ", ".join(entities.get('organizations', ['N/A'])))
194
+
195
+ # Named Entities from spaCy
196
+ st.subheader("🏷️ Named Entities")
197
+ entities = extract_entities(news_text, nlp)
198
+ df = pd.DataFrame(entities, columns=["Entity", "Type"])
199
+ st.dataframe(df)
200
+
201
+ # Knowledge Graph Visualization
202
+ st.subheader("πŸ•ΈοΈ Knowledge Graph")
203
+ fig = generate_knowledge_graph_viz(news_text, nlp, tokenizer, model)
204
+ st.plotly_chart(fig, use_container_width=True)
205
+
206
+ # Analysis Reasoning
207
+ st.subheader("πŸ’­ Analysis Reasoning")
208
+ for point in gemini_result.get('gemini_analysis', {}).get('reasoning', ['N/A']):
209
+ st.write(f"β€’ {point}")
210
 
211
+ except Exception as e:
212
+ st.error("Error processing analysis results")
213
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
 
216
  with st.expander("Named Entities"):