1010def dingo_demo (dataset_source , input_path , uploaded_file , data_format , column_content , rule_list , prompt_list , model ,
1111 key , api_url ):
1212 if not data_format :
13- return 'ValueError: data_format can not be empty, please input.' , None
13+ raise gr . Error ( 'ValueError: data_format can not be empty, please input.' )
1414 if not column_content :
15- return 'ValueError: column_content can not be empty, please input.' , None
15+ raise gr . Error ( 'ValueError: column_content can not be empty, please input.' )
1616 if not rule_list and not prompt_list :
17- return 'ValueError: rule_list and prompt_list can not be empty at the same time.' , None
17+ raise gr . Error ( 'ValueError: rule_list and prompt_list can not be empty at the same time.' )
1818
1919 # Handle input path based on dataset source
2020 if dataset_source == "hugging_face" :
2121 if not input_path :
22- return 'ValueError: input_path can not be empty for hugging_face dataset, please input.' , None
22+ raise gr . Error ( 'ValueError: input_path can not be empty for hugging_face dataset, please input.' )
2323 final_input_path = input_path
2424 else : # local
2525 if not uploaded_file :
26- return 'ValueError: Please upload a file for local dataset.' , None
26+ raise gr .Error ('Please upload a file for local dataset.' )
27+
28+ file_base_name = os .path .basename (uploaded_file .name )
29+ if not str (file_base_name ).endswith (('.jsonl' , '.json' , '.txt' )):
30+ raise gr .Error ('File format must be \' .jsonl\' , \' .json\' or \' .txt\' ' )
31+
2732 final_input_path = uploaded_file .name
2833
2934 input_data = {
@@ -34,20 +39,19 @@ def dingo_demo(dataset_source, input_path, uploaded_file, data_format, column_co
3439 "save_raw" : True ,
3540 "data_format" : data_format ,
3641 "column_content" : column_content ,
37- "custom_config" :
38- {
39- "rule_list" : rule_list ,
40- "prompt_list" : prompt_list ,
41- "llm_config" :
42- {
43- "detect_text_quality_detail" :
44- {
45- "model" : model ,
46- "key" : key ,
47- "api_url" : api_url ,
48- }
49- }
50- }
42+ "custom_config" :{
43+ "rule_list" : rule_list ,
44+ "prompt_list" : prompt_list ,
45+ "llm_config" :
46+ {
47+ "detect_text_quality_detail" :
48+ {
49+ "model" : model ,
50+ "key" : key ,
51+ "api_url" : api_url ,
52+ }
53+ }
54+ }
5155 }
5256 input_args = InputArgs (** input_data )
5357 executor = Executor .exec_map ["local" ](input_args )
0 commit comments