amcoff commited on
Commit
f996804
·
unverified ·
1 Parent(s): 7eee1a5

add script

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. README.md +1 -0
  3. ica.json +3 -0
  4. recept.py +104 -0
.gitattributes CHANGED
@@ -52,3 +52,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
52
  *.jpg filter=lfs diff=lfs merge=lfs -text
53
  *.jpeg filter=lfs diff=lfs merge=lfs -text
54
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
52
  *.jpg filter=lfs diff=lfs merge=lfs -text
53
  *.jpeg filter=lfs diff=lfs merge=lfs -text
54
  *.webp filter=lfs diff=lfs merge=lfs -text
55
+ ica.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ # Recept
ica.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31a19acccdc26ef5944d3b3e2245fe0144cff9e734bc3b19bc83c3d8822dd66d
3
+ size 20817394
recept.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import datasets
4
+
5
+ _DESCRIPTION = "Recipes scraped from ICA.se"
6
+
7
+ _TRAIN_DOWNLOAD_URL = "./ica.json"
8
+
9
+
10
+ difficulty_translations = {
11
+ "Enkel": "easy",
12
+ "Medel": "medium",
13
+ "Avancerad": "hard",
14
+ }
15
+
16
+
17
+ difficulties = ["easy", "medium", "hard"]
18
+
19
+
20
+ class Skolmat(datasets.GeneratorBasedBuilder):
21
+ def _info(self):
22
+ return datasets.DatasetInfo(
23
+ description=_DESCRIPTION,
24
+ features=datasets.Features(
25
+ {
26
+ "id": datasets.Value("int32"),
27
+ "title": datasets.Value("string"),
28
+ "preamble": datasets.Value("string"),
29
+ "url": datasets.Value("string"),
30
+ "cooking_time": datasets.Value("string"),
31
+ "difficulty": datasets.ClassLabel(names=difficulties),
32
+ "categories": datasets.Sequence(datasets.Value("string")),
33
+ "rating": datasets.Value("float32"),
34
+ "reviews": datasets.Value("int32"),
35
+ "instructions": datasets.Sequence(datasets.Value("string")),
36
+ "ingredeints": datasets.Sequence(
37
+ {
38
+ "heading": datasets.Value("string"),
39
+ "list": datasets.Sequence(
40
+ {
41
+ "name": datasets.Value("string"),
42
+ "amount": datasets.Value("string"),
43
+ }
44
+ ),
45
+ }
46
+ ),
47
+ "nutrition": {
48
+ "energy": datasets.Value("string"),
49
+ "fat": datasets.Value("string"),
50
+ "carbohydrates": datasets.Value("string"),
51
+ "protein": datasets.Value("string"),
52
+ },
53
+ }
54
+ ),
55
+ )
56
+
57
+ def _split_generators(self, dl_manager):
58
+ train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
59
+ return [
60
+ datasets.SplitGenerator(
61
+ name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}
62
+ ),
63
+ ]
64
+
65
+ def _generate_examples(self, filepath):
66
+ with open(filepath, encoding="utf8") as file:
67
+ for row in file:
68
+ recipe = json.loads(row)
69
+ difficulty = recipe.get("difficulty")
70
+ if difficulty is not None:
71
+ difficulty = difficulties.index(difficulty_translations[difficulty])
72
+
73
+ ingredient_sections = []
74
+
75
+ for section in recipe["ingredients"]:
76
+ ingredients = []
77
+ for ingredient in section["list"]:
78
+ ingredients.append(
79
+ {
80
+ "name": ingredient["ingr"],
81
+ "amount": ingredient["qty"],
82
+ }
83
+ )
84
+ ingredient_sections.append(
85
+ {
86
+ "heading": section["heading"],
87
+ "list": ingredients,
88
+ }
89
+ )
90
+
91
+ yield recipe["id"], {
92
+ "id": recipe["id"],
93
+ "title": recipe["title"],
94
+ "preamble": recipe["preamble"],
95
+ "url": recipe["absoluteUrl"],
96
+ "cooking_time": recipe.get("cookingTime"),
97
+ "difficulty": difficulty,
98
+ "categories": recipe["categories"],
99
+ "rating": recipe["rating"]["averageRating"],
100
+ "reviews": recipe["rating"]["numberOfVotes"],
101
+ "instructions": recipe["instructions"],
102
+ "ingredients": ingredient_sections,
103
+ "nutrition": recipe["nutrition"],
104
+ }