Skip to content

Commit a31351a

Browse files
authored
Merge pull request #33 from shijinpjlab/dev
feat: add header html in hf demo
2 parents 3c8e9ea + 98868f0 commit a31351a

File tree

2 files changed

+140
-20
lines changed

2 files changed

+140
-20
lines changed

examples/app_huggingface/app.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
from 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()
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<html><head>
2+
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css"> -->
3+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
4+
<style>
5+
.link-block {
6+
border: 1px solid transparent;
7+
border-radius: 24px;
8+
background-color: rgba(54, 54, 54, 1);
9+
cursor: pointer !important;
10+
}
11+
.link-block:hover {
12+
background-color: rgba(54, 54, 54, 0.75) !important;
13+
cursor: pointer !important;
14+
}
15+
.external-link {
16+
display: inline-flex;
17+
align-items: center;
18+
height: 36px;
19+
line-height: 36px;
20+
padding: 0 16px;
21+
cursor: pointer !important;
22+
}
23+
.external-link,
24+
.external-link:hover {
25+
cursor: pointer !important;
26+
}
27+
a {
28+
text-decoration: none;
29+
}
30+
</style></head>
31+
32+
<body>
33+
<div style="
34+
display: flex;
35+
flex-direction: column;
36+
justify-content: center;
37+
align-items: center;
38+
text-align: center;
39+
background: linear-gradient(45deg, #007bff 0%, #0056b3 100%);
40+
padding: 24px;
41+
gap: 24px;
42+
border-radius: 8px;
43+
">
44+
<div style="
45+
display: flex;
46+
flex-direction: column;
47+
align-items: center;
48+
gap: 16px;
49+
">
50+
<div style="display: flex; flex-direction: column; gap: 8px">
51+
<h1 style="
52+
font-size: 48px;
53+
color: #fafafa;
54+
margin: 0;
55+
font-family: 'Trebuchet MS', 'Lucida Sans Unicode',
56+
'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
57+
">
58+
Dingo
59+
</h1>
60+
</div>
61+
</div>
62+
63+
<p style="
64+
margin: 0;
65+
line-height: 1.6rem;
66+
font-size: 16px;
67+
color: #fafafa;
68+
opacity: 0.8;
69+
">
70+
Dingo: A Comprehensive Data Quality Evaluation Tool.<br>
71+
</p>
72+
<style>
73+
.link-block {
74+
display: inline-block;
75+
}
76+
.link-block + .link-block {
77+
margin-left: 20px;
78+
}
79+
</style>
80+
81+
<div class="column has-text-centered">
82+
<div class="publication-links">
83+
<!-- Code Link. -->
84+
<span class="link-block">
85+
<a href="https://github.com/DataEval/dingo" class="external-link button is-normal is-rounded is-dark" style="text-decoration: none; cursor: pointer">
86+
<span class="icon" style="margin-right: 4px">
87+
<i class="fab fa-github" style="color: white; margin-right: 4px"></i>
88+
</span>
89+
<span style="color: white">Code</span>
90+
</a>
91+
</span>
92+
93+
<!-- Paper Link. -->
94+
<span class="link-block">
95+
<a href="https://pypi.org/project/dingo-python/" class="external-link button is-normal is-rounded is-dark" style="text-decoration: none; cursor: pointer">
96+
<span class="icon" style="margin-right: 8px">
97+
<i class="fas fa-globe" style="color: white"></i>
98+
</span>
99+
<span style="color: white">Package</span>
100+
</a>
101+
</span>
102+
</div>
103+
</div>
104+
105+
<!-- New Demo Links -->
106+
</div>
107+
108+
109+
</body></html>

0 commit comments

Comments
 (0)