Spaces:
Sleeping
Sleeping
File size: 1,481 Bytes
efa0177 bad3ba3 efa0177 bad3ba3 efa0177 bad3ba3 efa0177 bad3ba3 efa0177 bad3ba3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import gradio as gr
import pandas as pd
import json
import markdown
# 从 Excel 文件中提取第一列的数据并解析 Markdown
def extract_and_parse_markdown(excel_file):
# 读取 Excel 文件
df = pd.read_excel(excel_file)
# 提取第一列的数据
first_column_data = df.iloc[:, 0].tolist()
# 解析 Markdown 字符串
parsed_texts = [markdown.markdown(text) for text in first_column_data]
return parsed_texts
# Gradio 界面函数
def questionnaire(question, option):
# 将用户的选择记录到 JSON 文件中
data = {
"question": question,
"selected_option": option
}
with open("responses.json", "a") as f:
json.dump(data, f)
f.write("\n")
return f"您选择了: {option}"
# 创建 Gradio 界面
def create_interface():
# 从 Excel 文件中提取并解析 Markdown
excel_file = "questions.xlsx" # 替换为你的 Excel 文件路径
questions = extract_and_parse_markdown(excel_file)
# 创建 Gradio 界面
iface = gr.Interface(
fn=questionnaire,
inputs=[
gr.Dropdown(choices=questions, label="请选择一个问题"),
gr.Radio(choices=["选项1", "选项2", "选项3"], label="请选择一个选项")
],
outputs="text",
title="问卷调查"
)
return iface
# 启动 Gradio 应用
if __name__ == "__main__":
iface = create_interface()
iface.launch() |