Update sentiment.py
Browse files- sentiment.py +8 -4
sentiment.py
CHANGED
@@ -50,18 +50,20 @@ model.classifier = torch.nn.Linear(768, 2)
|
|
50 |
|
51 |
|
52 |
def get_sentiment(query):
|
53 |
-
print(
|
54 |
filename = f"data/sentiment_analysis/{query}_results.pkl"
|
55 |
saved_data = load_data(filename)
|
56 |
|
57 |
if saved_data:
|
|
|
58 |
positive, negative, _ = saved_data
|
59 |
wordcloud = f'static/images/wordcloud/{query}_cloud.png'
|
60 |
return positive, negative, wordcloud
|
61 |
else:
|
62 |
-
|
63 |
results = get_reddit_results(query)
|
64 |
if not results:
|
|
|
65 |
error = "No results found for query"
|
66 |
return error
|
67 |
|
@@ -73,11 +75,11 @@ def get_sentiment(query):
|
|
73 |
|
74 |
|
75 |
def get_reddit_results(query):
|
76 |
-
print(
|
77 |
sub = reddit.subreddit('noveltranslations+progressionfantasy')
|
78 |
results = sub.search(query, limit=1)
|
79 |
|
80 |
-
print(results)
|
81 |
return list(results)
|
82 |
|
83 |
|
@@ -103,6 +105,7 @@ def analyze_comments(results, query):
|
|
103 |
comments_for_cloud = []
|
104 |
|
105 |
for submission in results:
|
|
|
106 |
submission.comments.replace_more(limit=None)
|
107 |
all_comments = submission.comments.list()
|
108 |
|
@@ -110,6 +113,7 @@ def analyze_comments(results, query):
|
|
110 |
comment_body = comment.body
|
111 |
|
112 |
text = transform_text(comment_body)
|
|
|
113 |
comments_for_cloud.append(comment_body)
|
114 |
|
115 |
if text:
|
|
|
50 |
|
51 |
|
52 |
def get_sentiment(query):
|
53 |
+
print('inside get sentiment')
|
54 |
filename = f"data/sentiment_analysis/{query}_results.pkl"
|
55 |
saved_data = load_data(filename)
|
56 |
|
57 |
if saved_data:
|
58 |
+
print('inside saved_data')
|
59 |
positive, negative, _ = saved_data
|
60 |
wordcloud = f'static/images/wordcloud/{query}_cloud.png'
|
61 |
return positive, negative, wordcloud
|
62 |
else:
|
63 |
+
print(' inside else not saved data')
|
64 |
results = get_reddit_results(query)
|
65 |
if not results:
|
66 |
+
print('no results')
|
67 |
error = "No results found for query"
|
68 |
return error
|
69 |
|
|
|
75 |
|
76 |
|
77 |
def get_reddit_results(query):
|
78 |
+
print('inside get reddit result')
|
79 |
sub = reddit.subreddit('noveltranslations+progressionfantasy')
|
80 |
results = sub.search(query, limit=1)
|
81 |
|
82 |
+
print(results[0])
|
83 |
return list(results)
|
84 |
|
85 |
|
|
|
105 |
comments_for_cloud = []
|
106 |
|
107 |
for submission in results:
|
108 |
+
print('inside submission')
|
109 |
submission.comments.replace_more(limit=None)
|
110 |
all_comments = submission.comments.list()
|
111 |
|
|
|
113 |
comment_body = comment.body
|
114 |
|
115 |
text = transform_text(comment_body)
|
116 |
+
print(text)
|
117 |
comments_for_cloud.append(comment_body)
|
118 |
|
119 |
if text:
|