diff --git a/examples/app_huggingface/app.py b/app_gradio/app.py similarity index 83% rename from examples/app_huggingface/app.py rename to app_gradio/app.py index fa795ad3..2f23417a 100644 --- a/examples/app_huggingface/app.py +++ b/app_gradio/app.py @@ -10,20 +10,25 @@ def dingo_demo(dataset_source, input_path, uploaded_file, data_format, column_content, rule_list, prompt_list, model, key, api_url): if not data_format: - return 'ValueError: data_format can not be empty, please input.', None + raise gr.Error('ValueError: data_format can not be empty, please input.') if not column_content: - return 'ValueError: column_content can not be empty, please input.', None + raise gr.Error('ValueError: column_content can not be empty, please input.') if not rule_list and not prompt_list: - return 'ValueError: rule_list and prompt_list can not be empty at the same time.', None + raise gr.Error('ValueError: rule_list and prompt_list can not be empty at the same time.') # Handle input path based on dataset source if dataset_source == "hugging_face": if not input_path: - return 'ValueError: input_path can not be empty for hugging_face dataset, please input.', None + raise gr.Error('ValueError: input_path can not be empty for hugging_face dataset, please input.') final_input_path = input_path else: # local if not uploaded_file: - return 'ValueError: Please upload a file for local dataset.', None + raise gr.Error('Please upload a file for local dataset.') + + file_base_name = os.path.basename(uploaded_file.name) + if not str(file_base_name).endswith(('.jsonl', '.json', '.txt')): + raise gr.Error('File format must be \'.jsonl\', \'.json\' or \'.txt\'') + final_input_path = uploaded_file.name input_data = { @@ -34,20 +39,19 @@ def dingo_demo(dataset_source, input_path, uploaded_file, data_format, column_co "save_raw": True, "data_format": data_format, "column_content": column_content, - "custom_config": - { - "rule_list": rule_list, - "prompt_list": prompt_list, - "llm_config": - { - "detect_text_quality_detail": - { - "model": model, - "key": key, - "api_url": api_url, - } - } - } + "custom_config":{ + "rule_list": rule_list, + "prompt_list": prompt_list, + "llm_config": + { + "detect_text_quality_detail": + { + "model": model, + "key": key, + "api_url": api_url, + } + } + } } input_args = InputArgs(**input_data) executor = Executor.exec_map["local"](input_args) diff --git a/examples/app_huggingface/header.html b/app_gradio/header.html similarity index 100% rename from examples/app_huggingface/header.html rename to app_gradio/header.html