sjzhongmou commited on
add dingo test
Browse files
app.py
CHANGED
|
@@ -1,7 +1,62 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
+
from dingo.exec import Executor
|
| 5 |
+
from dingo.io import InputArgs
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def dingo_demo(input_path, data_format, column_content, input_rules, input_prompts, key, api_url):
|
| 9 |
+
if not input_path:
|
| 10 |
+
return 'ValueError: input_path can not be empty, please input.'
|
| 11 |
+
if not data_format:
|
| 12 |
+
return 'ValueError: data_format can not be empty, please input.'
|
| 13 |
+
if not column_content:
|
| 14 |
+
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.'
|
| 17 |
+
|
| 18 |
+
input_data = {
|
| 19 |
+
"input_path": input_path,
|
| 20 |
+
"data_format": data_format,
|
| 21 |
+
"column_content": column_content,
|
| 22 |
+
"custom_config":
|
| 23 |
+
{
|
| 24 |
+
"rule_list": input_rules,
|
| 25 |
+
"prompt_list": input_prompts,
|
| 26 |
+
"llm_config":
|
| 27 |
+
{
|
| 28 |
+
"detect_text_quality_detail":
|
| 29 |
+
{
|
| 30 |
+
"key": key,
|
| 31 |
+
"api_url": api_url,
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
input_args = InputArgs(**input_data)
|
| 37 |
+
executor = Executor.exec_map["local"](input_args)
|
| 38 |
+
result = executor.execute()
|
| 39 |
+
summary = result[0].to_dict()
|
| 40 |
+
return json.dumps(summary, indent=4)
|
| 41 |
+
|
| 42 |
|
| 43 |
+
if __name__ == '__main__':
|
| 44 |
+
rule_options = ['RuleAbnormalChar', 'RuleAbnormalHtml', 'RuleContentNull', 'RuleContentShort', 'RuleEnterAndSpace', 'RuleOnlyUrl']
|
| 45 |
+
prompt_options = ['PromptRepeat', 'PromptContentChaos']
|
| 46 |
|
| 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")
|
| 62 |
+
demo.launch()
|