Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,23 +13,24 @@ def load_jsonl(file):
|
|
13 |
def random_data_viewer(file):
|
14 |
"""随机抽取一条数据并格式化输出"""
|
15 |
if file is None:
|
16 |
-
return "请上传一个
|
17 |
|
18 |
data = load_jsonl(file)
|
19 |
if len(data) == 0:
|
20 |
return "文件为空或格式不正确!"
|
21 |
|
22 |
random_entry = random.choice(data)
|
23 |
-
|
|
|
24 |
return output
|
25 |
|
26 |
# 创建Gradio界面
|
27 |
iface = gr.Interface(
|
28 |
fn=random_data_viewer,
|
29 |
inputs=gr.File(file_types=[".jsonl"], label="上传JSONL文件"),
|
30 |
-
outputs=gr.
|
31 |
title="JSONL 数据查看器",
|
32 |
-
description="上传一个JSONL文件,随机展示其中一条数据。"
|
33 |
)
|
34 |
|
35 |
# 启动Gradio应用
|
|
|
13 |
def random_data_viewer(file):
|
14 |
"""随机抽取一条数据并格式化输出"""
|
15 |
if file is None:
|
16 |
+
return "请上传一个JSONL文件!"
|
17 |
|
18 |
data = load_jsonl(file)
|
19 |
if len(data) == 0:
|
20 |
return "文件为空或格式不正确!"
|
21 |
|
22 |
random_entry = random.choice(data)
|
23 |
+
# 将数据格式化为Markdown形式
|
24 |
+
output = "\n".join([f"**{key}**: {value}" for key, value in random_entry.items()])
|
25 |
return output
|
26 |
|
27 |
# 创建Gradio界面
|
28 |
iface = gr.Interface(
|
29 |
fn=random_data_viewer,
|
30 |
inputs=gr.File(file_types=[".jsonl"], label="上传JSONL文件"),
|
31 |
+
outputs=gr.Textbox(label="随机数据", lines=10, max_lines=20), # 使用Textbox组件显示Markdown
|
32 |
title="JSONL 数据查看器",
|
33 |
+
description="上传一个JSONL文件,随机展示其中一条数据。",
|
34 |
)
|
35 |
|
36 |
# 启动Gradio应用
|