Qifan Zhang commited on
Commit
8f29b1d
1 Parent(s): 91b8d62

fear: add traceback

Browse files
Files changed (1) hide show
  1. app.py +25 -23
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
- # try:
29
- # load file
30
- if file:
31
- df = read_data(file.name)
32
- elif text:
33
- string_io = StringIO(text)
34
- df = pd.read_csv(string_io)
35
- assert len(df) >= 1, 'No input data'
36
- else:
37
- raise Exception('No input data')
38
 
39
- # process
40
- if task_name == 'Originality':
41
- df = pipeline.p0_originality(df, model_name, pooling)
42
- elif task_name == 'Flexibility':
43
- df = pipeline.p1_flexibility(df, model_name, pooling)
44
- else:
45
- raise Exception('Task not supported')
 
 
 
 
 
46
 
47
- # save
48
- path = 'output.csv'
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