jpdiazpardo commited on
Commit
b8a333c
1 Parent(s): 039ef51

Upload 5 files

Browse files
functions/charts.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import plotly.graph_objects as go
2
+
3
+ def add_emoji(emotions_list):
4
+ for s in range(len(emotions_list)):
5
+ if emotions_list[s]=="surprise": emotions_list[s]="surprise 😲"
6
+ elif emotions_list[s]=="joy": emotions_list[s]="joy 😀"
7
+ elif emotions_list[s]=="anger": emotions_list[s]="anger 🤬"
8
+ elif emotions_list[s]=="neutral": emotions_list[s]="neutral 😐"
9
+ elif emotions_list[s]=="disgust": emotions_list[s]="disgust 🤢"
10
+ elif emotions_list[s]=="fear": emotions_list[s]="fear 😨"
11
+ elif emotions_list[s]=="sadness": emotions_list[s]="sadness 😭"
12
+ else: print(s)
13
+
14
+ return emotions_list
15
+
16
+
17
+ def spider_chart(dictionary):
18
+
19
+ fig = go.Figure(data=go.Scatterpolar(
20
+ r=[round(v*100,2) for v in dictionary.values()],
21
+ theta= add_emoji([k for k in dictionary.keys()]),
22
+ fill='toself'))
23
+
24
+ fig.update_layout(
25
+ polar=dict(
26
+ radialaxis=dict(
27
+ visible=True
28
+ ),
29
+ ),
30
+ showlegend=False,
31
+ width = 400, height = 400,
32
+ title = "Audio Sentiment Analysis", title_x=0.5)
33
+
34
+ return fig
functions/dictionaries.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def transform_dict(list_dic):
2
+ '''Takes a list of dictionaries and converts the values inside the 'label' key
3
+ into a new key and assigns the values of the 'score' key into the new values of the new dictionary.
4
+ returns: dictionary'''
5
+
6
+ new_dicts = {}
7
+ for original_dict in list_dic:
8
+ key = original_dict['label']
9
+ value = original_dict['score']
10
+ new_dicts[key] = value
11
+
12
+ return new_dicts
13
+
14
+
15
+ def calculate_average(list_of_dicts):
16
+ '''Calculates the average value across all keys from a list of dictionaries'''
17
+ sum_dict = {}
18
+ count_dict = {}
19
+
20
+ # Step 1 and 2
21
+ for dictionary in list_of_dicts:
22
+ for key, value in dictionary.items():
23
+ if key in sum_dict:
24
+ sum_dict[key] += value
25
+ count_dict[key] += 1
26
+ else:
27
+ sum_dict[key] = value
28
+ count_dict[key] = 1
29
+
30
+ average_dict = {}
31
+
32
+ # Step 5
33
+ for key in sum_dict:
34
+ average_dict[key] = sum_dict[key] / count_dict[key]
35
+
36
+ return average_dict
functions/icon.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def generate_icon(icon):
2
+ if icon == 'linkedin':
3
+ unicodigo = '<i style="font-size:24px" class="fa">&#xf08c;</i>'
4
+
5
+ elif icon=="github":
6
+ unicodigo = '<i style="font-size:24px" class="fa">&#xf09b;</i>'
7
+
8
+ else:
9
+ None
10
+
11
+ html = ("<html>"
12
+ '<head>'
13
+ "<title>Font Awesome Icons</title>"
14
+ '<meta name="viewport" content="width=device-width, initial-scale=1">'
15
+ '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">'
16
+ "</head>"
17
+ "<body>"
18
+ f"{unicodigo}"
19
+ "</body>"
20
+ "</html>")
21
+
22
+ return html
functions/timestamp.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def format_timestamp(seconds: float, always_include_hours: bool = False, decimal_marker: str = "."):
2
+ if seconds is not None:
3
+ milliseconds = round(seconds * 1000.0)
4
+
5
+ hours = milliseconds // 3_600_000
6
+ milliseconds -= hours * 3_600_000
7
+
8
+ minutes = milliseconds // 60_000
9
+ milliseconds -= minutes * 60_000
10
+
11
+ seconds = milliseconds // 1_000
12
+ milliseconds -= seconds * 1_000
13
+
14
+ hours_marker = f"{hours:02d}:" if always_include_hours or hours > 0 else ""
15
+ return f"{hours_marker}{minutes:02d}:{seconds:02d}{decimal_marker}{milliseconds:03d}"
16
+ else:
17
+ # we have a malformed timestamp so just return it as is
18
+ return seconds
functions/youtube.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from urllib.parse import parse_qs, urlparse
2
+
3
+ def get_youtube_video_id(url):
4
+ # Parse the URL using urlparse
5
+ parsed_url = urlparse(url)
6
+
7
+ # Extract the 'v' parameter from the query string
8
+ video_id = parse_qs(parsed_url.query).get('v')
9
+
10
+ if video_id:
11
+ return video_id[0]
12
+ else:
13
+ return None