Spaces:
Runtime error
Runtime error
Update app.py
#2
by
eengel7
- opened
app.py
CHANGED
@@ -14,6 +14,10 @@ negative_preds = grouped_predictions.get_group(0)
|
|
14 |
|
15 |
predictions_df['Prediction'] = predictions_df['Prediction'].map({0: 'Negative', 1: 'Neutral', 2: 'Positive'})
|
16 |
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def article_selection(sentiment):
|
19 |
if sentiment == "Positive":
|
@@ -38,29 +42,32 @@ def article_selection(sentiment):
|
|
38 |
|
39 |
def manual_label():
|
40 |
# Selecting random row from batch data
|
|
|
41 |
random_sample = predictions_df.sample()
|
42 |
-
print('hey')
|
43 |
-
#random_sample_ds = Dataset.from_pandas(random_sample)
|
44 |
-
#random_sample.to_csv('/Users/torileatherman/Github/ID2223_scalable_machine_learning/news_articles_sentiment/sample.csv', index=False)
|
45 |
-
#random_sample_ds.push_to_hub('torileatherman/sample', index=False)
|
46 |
random_headline = random_sample['Headline_string'].iloc[0]
|
47 |
random_prediction = random_sample['Prediction'].iloc[0]
|
|
|
48 |
return random_headline, random_prediction
|
49 |
|
50 |
|
51 |
def thanks(sentiment):
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
#labeled_sentiments = Dataset.from_pandas(labeled_sentiments)
|
61 |
-
#labeled_sentiments.push_to_hub("torileatherman/"+counter+"labeled_data")
|
62 |
-
return f"""Thank you for making our model better!"""
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
description1 = '''
|
66 |
This application recommends news articles depending on the sentiment of the headline.
|
|
|
14 |
|
15 |
predictions_df['Prediction'] = predictions_df['Prediction'].map({0: 'Negative', 1: 'Neutral', 2: 'Positive'})
|
16 |
|
17 |
+
# Load training data set
|
18 |
+
dataset = load_dataset("eengel7/sentiment_analysis_training", split='train')
|
19 |
+
training_df = pd.DataFrame(dataset)
|
20 |
+
random_sample = {}
|
21 |
|
22 |
def article_selection(sentiment):
|
23 |
if sentiment == "Positive":
|
|
|
42 |
|
43 |
def manual_label():
|
44 |
# Selecting random row from batch data
|
45 |
+
global random_sample
|
46 |
random_sample = predictions_df.sample()
|
|
|
|
|
|
|
|
|
47 |
random_headline = random_sample['Headline_string'].iloc[0]
|
48 |
random_prediction = random_sample['Prediction'].iloc[0]
|
49 |
+
|
50 |
return random_headline, random_prediction
|
51 |
|
52 |
|
53 |
def thanks(sentiment):
|
54 |
+
|
55 |
+
# Create int label
|
56 |
+
mapping = gender = {'Negative': 0,'Neutral': 1, 'Positive':2}
|
57 |
+
sentiment = int(mapping[sentiment])
|
58 |
+
|
59 |
+
global training_df
|
60 |
+
# Append training data set
|
61 |
+
training_df = training_df.append({'Sentiment': sentiment, 'Headline_string': random_sample['Headline_string'].iloc[0], 'Headline': random_sample['Headline'].iloc[0] }, ignore_index=True)
|
|
|
|
|
|
|
62 |
|
63 |
+
# Upload training data set
|
64 |
+
ds = Dataset.from_pandas(training_df)
|
65 |
+
try:
|
66 |
+
ds.push_to_hub("eengel7/sentiment_analysis_training")
|
67 |
+
except StopIteration:
|
68 |
+
pass
|
69 |
+
|
70 |
+
return f"""Thank you for making our model better! """
|
71 |
|
72 |
description1 = '''
|
73 |
This application recommends news articles depending on the sentiment of the headline.
|