Spaces:
Runtime error
Runtime error
add json file loader
Browse files- ape/ape.py +3 -1
- ape/instance.py +12 -0
ape/ape.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# -*-coding:utf-8 -*-
|
2 |
from glob import glob
|
3 |
import pandas as pd
|
4 |
-
from ape.instance import Instance, LoadFactory, upload_file
|
5 |
from ape.llm import LLMGPT
|
6 |
from functools import partial
|
7 |
from itertools import chain
|
@@ -11,6 +11,8 @@ def load_task(task, file):
|
|
11 |
global instance
|
12 |
if task:
|
13 |
loader = LoadFactory[task]
|
|
|
|
|
14 |
else:
|
15 |
loader = partial(upload_file, file=file.name)
|
16 |
instance = Instance.from_file(loader)
|
|
|
1 |
# -*-coding:utf-8 -*-
|
2 |
from glob import glob
|
3 |
import pandas as pd
|
4 |
+
from ape.instance import Instance, LoadFactory, upload_file, upload_json
|
5 |
from ape.llm import LLMGPT
|
6 |
from functools import partial
|
7 |
from itertools import chain
|
|
|
11 |
global instance
|
12 |
if task:
|
13 |
loader = LoadFactory[task]
|
14 |
+
elif 'json' in file.name:
|
15 |
+
loader = partial(upload_json, file=file.name)
|
16 |
else:
|
17 |
loader = partial(upload_file, file=file.name)
|
18 |
instance = Instance.from_file(loader)
|
ape/instance.py
CHANGED
@@ -100,6 +100,15 @@ def upload_file(file):
|
|
100 |
return tuple_list
|
101 |
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
def load_entity(file='./ape/data/entity_train.json'):
|
104 |
data = []
|
105 |
raw_data = json.load(open(file, encoding='UTF8'))
|
@@ -140,3 +149,6 @@ if __name__ == '__main__':
|
|
140 |
print(instance2.display(instance2.train_samples))
|
141 |
train_iter = instance2.get_train_iter()
|
142 |
print(next(train_iter))
|
|
|
|
|
|
|
|
100 |
return tuple_list
|
101 |
|
102 |
|
103 |
+
def upload_json(file):
|
104 |
+
tuple_list = []
|
105 |
+
with open(file, 'r', encoding='UTF-8') as f:
|
106 |
+
for i in f.readlines():
|
107 |
+
data = json.loads(i.strip())
|
108 |
+
tuple_list.append((data['input'],data['output']))
|
109 |
+
return tuple_list
|
110 |
+
|
111 |
+
|
112 |
def load_entity(file='./ape/data/entity_train.json'):
|
113 |
data = []
|
114 |
raw_data = json.load(open(file, encoding='UTF8'))
|
|
|
149 |
print(instance2.display(instance2.train_samples))
|
150 |
train_iter = instance2.get_train_iter()
|
151 |
print(next(train_iter))
|
152 |
+
|
153 |
+
|
154 |
+
data = upload_json('./ape/data/question_paraphrase_classification.json')
|