theodotus commited on
Commit
4bf038a
·
1 Parent(s): 3a41fb9

Added image and description utils

Browse files
Files changed (1) hide show
  1. utils.py +17 -1
utils.py CHANGED
@@ -5,6 +5,7 @@ import json
5
  class Test:
6
  def __init__(self):
7
  self.data = self.read_test_data()
 
8
 
9
  def __len__(self):
10
  return len(self.data)
@@ -15,6 +16,13 @@ class Test:
15
  test_data = json.load(f)
16
  return test_data
17
 
 
 
 
 
 
 
 
18
  def get_question(self, idx):
19
  question = self.data[idx]["question"]
20
  return question
@@ -22,4 +30,12 @@ class Test:
22
  def get_answers(self, idx):
23
  responces = self.data[idx]["responces"]
24
  answers = [responce["answer"] for responce in responces]
25
- return answers
 
 
 
 
 
 
 
 
 
5
  class Test:
6
  def __init__(self):
7
  self.data = self.read_test_data()
8
+ self.descriptions = self.read_image_descriptions()
9
 
10
  def __len__(self):
11
  return len(self.data)
 
16
  test_data = json.load(f)
17
  return test_data
18
 
19
+ @staticmethod
20
+ def read_image_descriptions():
21
+ with open("images/descriptions.txt") as f:
22
+ lines = f.readlines()
23
+ clean_lines = [line.strip() for line in lines]
24
+ return clean_lines
25
+
26
  def get_question(self, idx):
27
  question = self.data[idx]["question"]
28
  return question
 
30
  def get_answers(self, idx):
31
  responces = self.data[idx]["responces"]
32
  answers = [responce["answer"] for responce in responces]
33
+ return answers
34
+
35
+ def get_description(self, idx):
36
+ description = self.descriptions[idx]
37
+ return description
38
+
39
+ def get_image_path(self, idx):
40
+ image_path = f"images/{idx}.jpg"
41
+ return image_path