Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ def load_jsonl(file):
|
|
11 |
return data
|
12 |
|
13 |
def random_data_viewer(file):
|
14 |
-
"""
|
15 |
if file is None:
|
16 |
return "请上传一个jsonl文件!"
|
17 |
|
@@ -20,14 +20,15 @@ def random_data_viewer(file):
|
|
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 |
)
|
|
|
11 |
return data
|
12 |
|
13 |
def random_data_viewer(file):
|
14 |
+
"""随机抽取一条数据并格式化输出为Markdown"""
|
15 |
if file is None:
|
16 |
return "请上传一个jsonl文件!"
|
17 |
|
|
|
20 |
return "文件为空或格式不正确!"
|
21 |
|
22 |
random_entry = random.choice(data)
|
23 |
+
# 将每个字段的value格式化为Markdown
|
24 |
+
output = "\n".join([f"**{key}:**\n\n{value}\n" 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.Markdown(label="随机数据"), # 使用Markdown组件
|
32 |
title="JSONL 数据查看器",
|
33 |
description="上传一个JSONL文件,随机展示其中一条数据。"
|
34 |
)
|