Spaces:
Running
Running
Commit
·
fff91af
1
Parent(s):
7ac98e2
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from tqdm import tqdm
|
|
7 |
|
8 |
import altair as alt
|
9 |
import matplotlib.pyplot as plt
|
10 |
-
import
|
11 |
|
12 |
from transformers import AutoTokenizer, AutoConfig, AutoModel, AutoModelForSequenceClassification
|
13 |
|
@@ -177,10 +177,44 @@ def freq(output_file, input_checks):
|
|
177 |
|
178 |
|
179 |
def dist(output_file, input_checks):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
data = pd.DataFrame({
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
|
185 |
domain = ['neutral', 'anger', 'fear', 'joy', 'love', 'sadness']
|
186 |
range_ = ['#999999', '#b22222', '#663399', '#ffcc00', '#db7093', '#6495ed']
|
|
|
7 |
|
8 |
import altair as alt
|
9 |
import matplotlib.pyplot as plt
|
10 |
+
from datetime import date, timedelta
|
11 |
|
12 |
from transformers import AutoTokenizer, AutoConfig, AutoModel, AutoModelForSequenceClassification
|
13 |
|
|
|
177 |
|
178 |
|
179 |
def dist(output_file, input_checks):
|
180 |
+
#data = pd.DataFrame({
|
181 |
+
#'Date': ['1/1', '1/1', '1/1', '1/1', '1/1', '1/1', '2/1', '2/1', '2/1', '2/1', '2/1', '2/1', '3/1', '3/1', '3/1', '3/1', '3/1', '3/1'],
|
182 |
+
#'Frequency': [3, 5, 1, 8, 2, 3, 4, 7, 1, 12, 4, 2, 3, 6, 3, 10, 3, 4],
|
183 |
+
#'Emotion category': ['neutral', 'anger', 'fear', 'joy', 'love', 'sadness', 'neutral', 'anger', 'fear', 'joy', 'love', 'sadness', 'neutral', 'anger', 'fear', 'joy', 'love', 'sadness']})
|
184 |
+
|
185 |
+
f = open("showcase/data.txt", 'r')
|
186 |
+
data = f.read().split("\n")
|
187 |
+
f.close()
|
188 |
+
data = [line.split("\t") for line in data[1:-1]]
|
189 |
+
|
190 |
+
freq_dict = {}
|
191 |
+
for line in data:
|
192 |
+
dat = str(date(2000+int(line[0].split("/")[2]), int(line[0].split("/")[1]), int(line[0].split("/")[0])))
|
193 |
+
if dat not in freq_dict.keys():
|
194 |
+
freq_dict[dat] = {}
|
195 |
+
if line[1] not in freq_dict[dat].keys():
|
196 |
+
freq_dict[dat][line[1]] = 1
|
197 |
+
else:
|
198 |
+
freq_dict[dat][line[1]] += 1
|
199 |
+
else:
|
200 |
+
if line[1] not in freq_dict[dat].keys():
|
201 |
+
freq_dict[dat][line[1]] = 1
|
202 |
+
else:
|
203 |
+
freq_dict[dat][line[1]] += 1
|
204 |
+
|
205 |
+
start_date = date(2000+int(data[0][0].split("/")[2]), int(data[0][0].split("/")[1]), int(data[0][0].split("/")[0]))
|
206 |
+
end_date = date(2000+int(data[-1][0].split("/")[2]), int(data[-1][0].split("/")[1]), int(data[-1][0].split("/")[0]))
|
207 |
+
delta = end_date - start_date # returns timedelta
|
208 |
+
date_range = [str(start_date + timedelta(days=i)) for i in range(delta.days + 1)]
|
209 |
+
|
210 |
+
dates = [dat for dat in date_range for i in range(6)]
|
211 |
+
frequency = [freq_dict[dat][emotion] if (dat in freq_dict.keys() and emotion in freq_dict[dat].keys()) else 0 for dat in date_range for emotion in ['neutral', 'anger', 'fear', 'joy', 'love', 'sadness']]
|
212 |
+
categories = [emotion for dat in date_range for emotion in ['neutral', 'anger', 'fear', 'joy', 'love', 'sadness']]
|
213 |
+
|
214 |
data = pd.DataFrame({
|
215 |
+
'Date': dates,
|
216 |
+
'Frequency': frequency,
|
217 |
+
'Emotion category': categories})
|
218 |
|
219 |
domain = ['neutral', 'anger', 'fear', 'joy', 'love', 'sadness']
|
220 |
range_ = ['#999999', '#b22222', '#663399', '#ffcc00', '#db7093', '#6495ed']
|