Upload NewDataset.py with huggingface_hub
Browse files- NewDataset.py +5 -5
NewDataset.py
CHANGED
|
@@ -6,7 +6,7 @@ import zipfile
|
|
| 6 |
|
| 7 |
class NewDataset(datasets.GeneratorBasedBuilder):
|
| 8 |
def _info(self):
|
| 9 |
-
return datasets.DatasetInfo(features=datasets.Features({'
|
| 10 |
|
| 11 |
def extract_all(self, dir):
|
| 12 |
zip_files = glob(dir+'/**/**.zip', recursive=True)
|
|
@@ -30,7 +30,7 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
| 30 |
|
| 31 |
def read_image(self, filepath):
|
| 32 |
if filepath.endswith('.jpg') or filepath.endswith('.png'):
|
| 33 |
-
raw_data = {'
|
| 34 |
else:
|
| 35 |
raw_data = {'text':[open(filepath).read()]}
|
| 36 |
return pd.DataFrame(raw_data)
|
|
@@ -42,10 +42,10 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
| 42 |
dfs = [df]
|
| 43 |
dfs.append(self.read_image(filepaths['targets1'][i]))
|
| 44 |
df = pd.concat(dfs, axis = 1)
|
| 45 |
-
if len(df.columns) !=
|
| 46 |
continue
|
| 47 |
-
df.columns = ['
|
| 48 |
for _, record in df.iterrows():
|
| 49 |
-
yield str(_id), {'
|
| 50 |
_id += 1
|
| 51 |
|
|
|
|
| 6 |
|
| 7 |
class NewDataset(datasets.GeneratorBasedBuilder):
|
| 8 |
def _info(self):
|
| 9 |
+
return datasets.DatasetInfo(features=datasets.Features({'image':datasets.Image(),'text':datasets.Value('string')}))
|
| 10 |
|
| 11 |
def extract_all(self, dir):
|
| 12 |
zip_files = glob(dir+'/**/**.zip', recursive=True)
|
|
|
|
| 30 |
|
| 31 |
def read_image(self, filepath):
|
| 32 |
if filepath.endswith('.jpg') or filepath.endswith('.png'):
|
| 33 |
+
raw_data = {'bytes':[filepath]}
|
| 34 |
else:
|
| 35 |
raw_data = {'text':[open(filepath).read()]}
|
| 36 |
return pd.DataFrame(raw_data)
|
|
|
|
| 42 |
dfs = [df]
|
| 43 |
dfs.append(self.read_image(filepaths['targets1'][i]))
|
| 44 |
df = pd.concat(dfs, axis = 1)
|
| 45 |
+
if len(df.columns) != 2:
|
| 46 |
continue
|
| 47 |
+
df.columns = ['image', 'text']
|
| 48 |
for _, record in df.iterrows():
|
| 49 |
+
yield str(_id), {'image':record['image'],'text':record['text']}
|
| 50 |
_id += 1
|
| 51 |
|