YixuanWang commited on
Commit
7154a46
·
verified ·
1 Parent(s): d227e5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -5,11 +5,8 @@ import torch
5
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
  from textblob import TextBlob
7
 
8
-
9
-
10
-
11
  # Load the dataset from the local file
12
- data = pd.read_csv('twitter_dataset.csv').head(1000)
13
 
14
  # Calculate sentiment polarity and popularity
15
  data['Sentiment'] = data['Text'].apply(lambda x: TextBlob(x).sentiment.polarity)
@@ -39,7 +36,7 @@ data['Fake_News_Prediction'] = predictions
39
  data['Credibility'] = data['Fake_News_Prediction'].apply(lambda x: 1 if x == 1 else -1)
40
 
41
  # Define the prediction and recommendation function
42
- def predict_and_recommend(title, text, visibility_weight, sentiment_weight, popularity_weight):
43
  # Adjust weights and calculate the final score
44
  total_weight = visibility_weight + sentiment_weight + popularity_weight
45
  visibility_weight /= total_weight
@@ -56,21 +53,22 @@ def predict_and_recommend(title, text, visibility_weight, sentiment_weight, popu
56
  top_100_data = data.nlargest(100, 'User_Final_Visibility_Score')
57
  recommended_data = top_100_data.sample(10)
58
 
59
- return recommended_data[['Text', 'User_Final_Visibility_Score']]
 
 
 
60
 
61
  # Set up Gradio interface
62
  iface = gr.Interface(
63
  fn=predict_and_recommend,
64
  inputs=[
65
- gr.Textbox(label="Title"),
66
- gr.Textbox(label="Text", lines=10),
67
  gr.Slider(0, 1, 0.5, label="Visibility Weight"),
68
  gr.Slider(0, 1, 0.3, label="Sentiment Weight"),
69
  gr.Slider(0, 1, 0.2, label="Popularity Weight")
70
  ],
71
- outputs="dataframe",
72
  title="Customizable Fake News Recommendation System",
73
  description="Adjust weights to receive customized tweet recommendations based on visibility, sentiment, and popularity."
74
  )
75
 
76
- iface.launch()
 
5
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
  from textblob import TextBlob
7
 
 
 
 
8
  # Load the dataset from the local file
9
+ data = pd.read_csv('twitter_dataset.csv')
10
 
11
  # Calculate sentiment polarity and popularity
12
  data['Sentiment'] = data['Text'].apply(lambda x: TextBlob(x).sentiment.polarity)
 
36
  data['Credibility'] = data['Fake_News_Prediction'].apply(lambda x: 1 if x == 1 else -1)
37
 
38
  # Define the prediction and recommendation function
39
+ def predict_and_recommend(visibility_weight, sentiment_weight, popularity_weight):
40
  # Adjust weights and calculate the final score
41
  total_weight = visibility_weight + sentiment_weight + popularity_weight
42
  visibility_weight /= total_weight
 
53
  top_100_data = data.nlargest(100, 'User_Final_Visibility_Score')
54
  recommended_data = top_100_data.sample(10)
55
 
56
+ # Format output with empty lines between tweets
57
+ output = "\n\n".join(f"**Tweet**: {row['Text']}\n**Score**: {row['User_Final_Visibility_Score']:.2f}"
58
+ for _, row in recommended_data.iterrows())
59
+ return output
60
 
61
  # Set up Gradio interface
62
  iface = gr.Interface(
63
  fn=predict_and_recommend,
64
  inputs=[
 
 
65
  gr.Slider(0, 1, 0.5, label="Visibility Weight"),
66
  gr.Slider(0, 1, 0.3, label="Sentiment Weight"),
67
  gr.Slider(0, 1, 0.2, label="Popularity Weight")
68
  ],
69
+ outputs="markdown",
70
  title="Customizable Fake News Recommendation System",
71
  description="Adjust weights to receive customized tweet recommendations based on visibility, sentiment, and popularity."
72
  )
73
 
74
+ iface.launch()