Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from sdoc_request import get_tianshu_response
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import time
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
# 设置页面标题
|
| 8 |
+
st.title("SDoc 问题智能分析")
|
| 9 |
+
|
| 10 |
+
# 创建文件上传组件
|
| 11 |
+
st.text("1. 少量问题,请访问链接提问。")
|
| 12 |
+
st.markdown("https://aiapi.sheincorp.cn/llm/#/scene/general_app/7180")
|
| 13 |
+
|
| 14 |
+
uploaded_file = st.file_uploader("2. 大量问题,请上传 Excel 文件,必须含有【问题描述】字段。", type=["xlsx"])
|
| 15 |
+
|
| 16 |
+
if uploaded_file is not None:
|
| 17 |
+
# 读取上传的 Excel 文件
|
| 18 |
+
sdoc_df = pd.read_excel(uploaded_file)
|
| 19 |
+
questions = sdoc_df["问题描述"].to_list()
|
| 20 |
+
|
| 21 |
+
# AI 智能分析
|
| 22 |
+
categories = []
|
| 23 |
+
modules = []
|
| 24 |
+
summaries = []
|
| 25 |
+
|
| 26 |
+
# 创建进度条
|
| 27 |
+
progress_bar = st.progress(0)
|
| 28 |
+
total_questions = len(questions)
|
| 29 |
+
|
| 30 |
+
for i, qs in enumerate(questions):
|
| 31 |
+
if qs and len(qs) > 0:
|
| 32 |
+
time.sleep(1)
|
| 33 |
+
params = {"HOA_USERINPUT": qs}
|
| 34 |
+
temp_result = get_tianshu_response(params)
|
| 35 |
+
try:
|
| 36 |
+
result = json.loads(temp_result)
|
| 37 |
+
except json.JSONDecodeError:
|
| 38 |
+
result = {"类别": '', "模块": '', "问题归类": ''}
|
| 39 |
+
st.warning(f"问题 '{qs}' 的返回结果不是有效的 JSON 格式。")
|
| 40 |
+
else:
|
| 41 |
+
result = {"类别": '', "模块": '', "问题归类": ''}
|
| 42 |
+
|
| 43 |
+
st.write(f"问题{i+1}: {qs}")
|
| 44 |
+
st.write(f"答案: {result}")
|
| 45 |
+
|
| 46 |
+
categories.append(result.get("类别"))
|
| 47 |
+
modules.append(result.get("模块"))
|
| 48 |
+
summaries.append(result.get("问题归类"))
|
| 49 |
+
|
| 50 |
+
# 更新进度条
|
| 51 |
+
progress_bar.progress((i + 1) / total_questions)
|
| 52 |
+
|
| 53 |
+
# 结果数据整理
|
| 54 |
+
sdoc_df['类别'] = categories
|
| 55 |
+
sdoc_df['模块'] = modules
|
| 56 |
+
sdoc_df['问题归类'] = summaries
|
| 57 |
+
|
| 58 |
+
# 将结果保存为 Excel 文件
|
| 59 |
+
output_file = "smart_analysis.xlsx"
|
| 60 |
+
sdoc_df.to_excel(output_file, index=0)
|
| 61 |
+
|
| 62 |
+
# 创建下载链接
|
| 63 |
+
with open(output_file, "rb") as file:
|
| 64 |
+
btn = st.download_button(
|
| 65 |
+
label="下载分析结果",
|
| 66 |
+
data=file,
|
| 67 |
+
file_name="smart_analysis.xlsx",
|
| 68 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 69 |
+
)
|
| 70 |
+
|