-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
31 lines (20 loc) · 874 Bytes
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from pathlib import Path
from typing import Any, Dict, List
from urllib.request import urlretrieve
def download_file(url: str) -> Path:
example_dirpath = Path(__file__).parent
data_dirpath = example_dirpath / "data"
data_dirpath.mkdir(exist_ok=True)
filepath = data_dirpath / Path(url).name
urlretrieve(url, filepath)
return filepath
# def print_emotions(emotions: List[Dict[str, Any]]) -> None:
# emotion_map = {e["name"]: e["score"] for e in emotions}
# for emotion in ["Joy", "Sadness", "Anger"]:
# print(f"- {emotion}: {emotion_map[emotion]:4f}")
def print_emotions(emotions: List[Dict[str, Any]]) -> None:
emotion_map = {e["score"]: e["name"] for e in emotions}
scores = list(emotion_map.keys())
scores.sort(reverse=True)
for i in range(5):
print(f"- {emotion_map[scores[i]]}: {scores[i]:4f}")