NKessler commited on
Commit
0283949
·
verified ·
1 Parent(s): dbe37cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -64,7 +64,7 @@ def analyze_article(text: str) -> dict:
64
  safe_text = text[:MAX_TEXT_LENGTH]
65
 
66
  # Sentiment Analysis
67
- sentiment_result = models["sentiment"](safe_text)[0]
68
  label = sentiment_result["label"].lower()
69
  score = sentiment_result["score"]
70
  if label == "negative":
@@ -75,7 +75,7 @@ def analyze_article(text: str) -> dict:
75
  sentiment_score = 0.0 # Neutral
76
 
77
  # Emotion Classification
78
- emotion_results = models["emotion"](safe_text)
79
 
80
  if isinstance(emotion_results, list) and isinstance(emotion_results[0], list):
81
  emotion_results = emotion_results[0]
@@ -244,9 +244,9 @@ def check_contradiction(text_a: str, text_b: str) -> dict:
244
  models = _load_nlp_models()
245
 
246
  combined_text = f"Source A argues: {text_a[:300]} Meanwhile, Source B argues: {text_b[:300]}"
247
-
248
  labels = ["opposing views", "supporting views", "unrelated topics"]
249
- result = models["theme"](combined_text, labels)
 
250
 
251
  top_label = result["labels"][0]
252
  score = result["scores"][0]
@@ -328,10 +328,21 @@ st.write("")
328
 
329
  # Execution button
330
  if st.button("Analyze and Compare Sources", use_container_width=True, type="primary"):
331
- with st.spinner("Analyzing framing semantics for both sources..."):
332
- st.session_state.results_a = analyze_article(user_article_a)
333
- st.session_state.results_b = analyze_article(user_article_b)
334
- st.session_state.nli_result = check_contradiction(user_article_a, user_article_b)
 
 
 
 
 
 
 
 
 
 
 
335
 
336
  # Analysis Display
337
  if st.session_state.results_a and st.session_state.results_b:
 
64
  safe_text = text[:MAX_TEXT_LENGTH]
65
 
66
  # Sentiment Analysis
67
+ sentiment_result = models["sentiment"](safe_text, truncation=True)[0]
68
  label = sentiment_result["label"].lower()
69
  score = sentiment_result["score"]
70
  if label == "negative":
 
75
  sentiment_score = 0.0 # Neutral
76
 
77
  # Emotion Classification
78
+ emotion_results = models["emotion"](safe_text, truncation=True)
79
 
80
  if isinstance(emotion_results, list) and isinstance(emotion_results[0], list):
81
  emotion_results = emotion_results[0]
 
244
  models = _load_nlp_models()
245
 
246
  combined_text = f"Source A argues: {text_a[:300]} Meanwhile, Source B argues: {text_b[:300]}"
 
247
  labels = ["opposing views", "supporting views", "unrelated topics"]
248
+
249
+ result = models["theme"](combined_text, labels, truncation=True)
250
 
251
  top_label = result["labels"][0]
252
  score = result["scores"][0]
 
328
 
329
  # Execution button
330
  if st.button("Analyze and Compare Sources", use_container_width=True, type="primary"):
331
+
332
+ text_a_clean = user_article_a.strip() if user_article_a else ""
333
+ text_b_clean = user_article_b.strip() if user_article_b else ""
334
+
335
+ if not text_a_clean or not text_b_clean:
336
+ st.warning("Please provide text or a valid URL for both Source A and Source B before analyzing.")
337
+
338
+ elif text_a_clean.startswith("Error:") or text_b_clean.startswith("Error:"):
339
+ st.error("One of the URLs could not be scraped. Please copy and paste the text directly.")
340
+
341
+ else:
342
+ with st.spinner("Analyzing framing semantics for both sources."):
343
+ st.session_state.results_a = analyze_article(text_a_clean)
344
+ st.session_state.results_b = analyze_article(text_b_clean)
345
+ st.session_state.nli_result = check_contradiction(text_a_clean, text_b_clean)
346
 
347
  # Analysis Display
348
  if st.session_state.results_a and st.session_state.results_b: