FlowerNet-EXP / app.py
ELVISIO's picture
Update app.py
bad3ba3 verified
raw
history blame
1.48 kB
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()