55from dingo .io import InputArgs
66
77
8- def dingo_demo (input_path , data_format , column_content , input_rules , input_prompts , key , api_url ):
8+ def dingo_demo (input_path , data_format , column_content , rule_list , prompt_list , key , api_url ):
99 if not input_path :
1010 return 'ValueError: input_path can not be empty, please input.'
1111 if not data_format :
1212 return 'ValueError: data_format can not be empty, please input.'
1313 if not column_content :
1414 return 'ValueError: column_content can not be empty, please input.'
15- if not input_rules and not input_prompts :
16- return 'ValueError: input_rules and input_prompts can not be empty at the same time.'
15+ if not rule_list and not prompt_list :
16+ return 'ValueError: rule_list and prompt_list can not be empty at the same time.'
1717
1818 input_data = {
1919 "input_path" : input_path ,
2020 "data_format" : data_format ,
2121 "column_content" : column_content ,
2222 "custom_config" :
2323 {
24- "rule_list" : input_rules ,
25- "prompt_list" : input_prompts ,
24+ "rule_list" : rule_list ,
25+ "prompt_list" : prompt_list ,
2626 "llm_config" :
2727 {
2828 "detect_text_quality_detail" :
@@ -44,19 +44,30 @@ def dingo_demo(input_path, data_format, column_content, input_rules, input_promp
4444 rule_options = ['RuleAbnormalChar' , 'RuleAbnormalHtml' , 'RuleContentNull' , 'RuleContentShort' , 'RuleEnterAndSpace' , 'RuleOnlyUrl' ]
4545 prompt_options = ['PromptRepeat' , 'PromptContentChaos' ]
4646
47- #接口创建函数
48- #fn设置处理函数,inputs设置输入接口组件,outputs设置输出接口组件
49- #fn,inputs,outputs都是必填函数
50- demo = gr .Interface (
51- fn = dingo_demo ,
52- inputs = [
53- gr .Textbox (value = 'chupei/format-jsonl' , placeholder = "please input huggingface dataset path" ),
54- gr .Dropdown (["jsonl" , "json" , "plaintext" , "listjson" ], label = "data_format" ),
55- gr .Textbox (value = "content" , placeholder = "please input column name of content in dataset" ),
56- gr .CheckboxGroup (choices = rule_options , label = "rule_list" ),
57- gr .CheckboxGroup (choices = prompt_options , label = "prompt_list" ),
58- 'text' ,
59- 'text' ,
60- ],
61- outputs = "text" )
47+ with open ("header.html" , "r" ) as file :
48+ header = file .read ()
49+ with gr .Blocks () as demo :
50+ gr .HTML (header )
51+ with gr .Row ():
52+ with gr .Column ():
53+ input_path = gr .Textbox (value = 'chupei/format-jsonl' , placeholder = "please input huggingface dataset path" , label = "input_path" )
54+ data_format = gr .Dropdown (["jsonl" , "json" , "plaintext" , "listjson" ], label = "data_format" )
55+ column_content = gr .Textbox (value = "content" , placeholder = "please input column name of content in dataset" , label = "column_content" )
56+ rule_list = gr .CheckboxGroup (choices = rule_options , label = "rule_list" )
57+ prompt_list = gr .CheckboxGroup (choices = prompt_options , label = "prompt_list" )
58+ key = gr .Textbox (placeholder = "If want to use llm, please input the key of it." , label = "key" )
59+ api_url = gr .Textbox (placeholder = "If want to use llm, please input the api_url of it." , label = "api_url" )
60+ with gr .Row ():
61+ submit_single = gr .Button (value = "Submit" , interactive = True , variant = "primary" )
62+ with gr .Column ():
63+ # 输出组件
64+ output = gr .Textbox (label = "output" )
65+
66+ submit_single .click (
67+ fn = dingo_demo ,
68+ inputs = [input_path , data_format , column_content , rule_list , prompt_list , key , api_url ],
69+ outputs = output
70+ )
71+
72+ # 启动界面
6273 demo .launch ()
0 commit comments