Qifan Zhang
commited on
Commit
·
8f29b1d
1
Parent(s):
91b8d62
fear: add traceback
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from io import StringIO
|
2 |
from typing import Optional
|
3 |
|
@@ -25,31 +26,32 @@ def process(
|
|
25 |
text: str,
|
26 |
file=None,
|
27 |
) -> (None, pd.DataFrame, str):
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
df.to_csv(path, index=False, encoding='utf-8-sig')
|
50 |
-
return None, df.iloc[:10], path
|
51 |
-
# except Exception as e:
|
52 |
-
# return {'Error': e}, None, None
|
53 |
|
54 |
|
55 |
# input
|
|
|
1 |
+
import traceback
|
2 |
from io import StringIO
|
3 |
from typing import Optional
|
4 |
|
|
|
26 |
text: str,
|
27 |
file=None,
|
28 |
) -> (None, pd.DataFrame, str):
|
29 |
+
try:
|
30 |
+
# load file
|
31 |
+
if file:
|
32 |
+
df = read_data(file.name)
|
33 |
+
elif text:
|
34 |
+
string_io = StringIO(text)
|
35 |
+
df = pd.read_csv(string_io)
|
36 |
+
assert len(df) >= 1, 'No input data'
|
37 |
+
else:
|
38 |
+
raise Exception('No input data')
|
39 |
|
40 |
+
# process
|
41 |
+
if task_name == 'Originality':
|
42 |
+
df = pipeline.p0_originality(df, model_name, pooling)
|
43 |
+
elif task_name == 'Flexibility':
|
44 |
+
df = pipeline.p1_flexibility(df, model_name, pooling)
|
45 |
+
else:
|
46 |
+
raise Exception('Task not supported')
|
47 |
+
|
48 |
+
# save
|
49 |
+
path = 'output.csv'
|
50 |
+
df.to_csv(path, index=False, encoding='utf-8-sig')
|
51 |
+
return None, df.iloc[:10], path
|
52 |
|
53 |
+
except:
|
54 |
+
return {'Info': 'Something wrong', 'Error': traceback.format_exc()}, None, None
|
|
|
|
|
|
|
|
|
55 |
|
56 |
|
57 |
# input
|