Zeamays3427 commited on
Commit
ad59972
Β·
verified Β·
1 Parent(s): 8ecc298

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -101,22 +101,43 @@ def predict_and_explain(title, text):
101
  # Predict whether the news is real or fake, and extract keywords
102
  label, fake_prob, real_prob, keywords = predict(title, text)
103
 
 
 
 
 
 
 
104
  # If the news is classified as fake, generate suggestions
105
  if label == 'Fake':
106
  suggestions = generate_suggestions(title, text, keywords)
107
  return f"""
 
 
108
  **Prediction**: Fake News
109
- **Probability**: {fake_prob:.2f}% Fake, {real_prob:.2f}% Real
110
- **Keywords**: {', '.join(keywords)}
111
- **Suggestions**:
 
 
 
 
 
 
112
  {suggestions}
113
  """
114
  else:
115
  # If the news is real, just show the prediction and keywords
116
  return f"""
 
 
117
  **Prediction**: Real News
118
- **Probability**: {real_prob:.2f}% Real, {fake_prob:.2f}% Fake
119
- **Keywords**: {', '.join(keywords)}
 
 
 
 
 
120
  """
121
 
122
  # Function to generate suggestions for fact-checking
 
101
  # Predict whether the news is real or fake, and extract keywords
102
  label, fake_prob, real_prob, keywords = predict(title, text)
103
 
104
+ # Format keywords with line breaks after every 5 keywords
105
+ formatted_keywords = []
106
+ for i in range(0, len(keywords), 5):
107
+ formatted_keywords.append(', '.join(keywords[i:i+5]))
108
+ keywords_text = ',\n'.join(formatted_keywords)
109
+
110
  # If the news is classified as fake, generate suggestions
111
  if label == 'Fake':
112
  suggestions = generate_suggestions(title, text, keywords)
113
  return f"""
114
+ ## πŸ” Analysis Results
115
+
116
  **Prediction**: Fake News
117
+
118
+ **Probability**:
119
+ - Fake: {fake_prob:.2f}%
120
+ - Real: {real_prob:.2f}%
121
+
122
+ **Keywords**:
123
+ {keywords_text}
124
+
125
+ **Fact-Checking Suggestions**:
126
  {suggestions}
127
  """
128
  else:
129
  # If the news is real, just show the prediction and keywords
130
  return f"""
131
+ ## πŸ” Analysis Results
132
+
133
  **Prediction**: Real News
134
+
135
+ **Probability**:
136
+ - Real: {real_prob:.2f}%
137
+ - Fake: {fake_prob:.2f}%
138
+
139
+ **Keywords**:
140
+ {keywords_text}
141
  """
142
 
143
  # Function to generate suggestions for fact-checking