Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,8 +140,8 @@ with gr.Blocks(theme=gr.themes.Soft(), title="EGISInsight") as demo:
|
|
| 140 |
# if __name__ == "__main__":
|
| 141 |
# demo.launch(server_name="0.0.0.0", share=True)
|
| 142 |
|
| 143 |
-
# ================== 大赛平台专用 API
|
| 144 |
-
from fastapi import FastAPI, File, UploadFile, Form
|
| 145 |
import uvicorn
|
| 146 |
from io import BytesIO
|
| 147 |
|
|
@@ -154,26 +154,32 @@ async def plugin_api(
|
|
| 154 |
timestamp: str = Form(...), # 平台传递的时间戳
|
| 155 |
signature: str = Form(...) # 平台传递的签名(可选校验)
|
| 156 |
):
|
| 157 |
-
#
|
| 158 |
-
|
| 159 |
-
print(f"
|
|
|
|
|
|
|
| 160 |
try:
|
| 161 |
-
#
|
| 162 |
excel_content = await file.read()
|
| 163 |
-
|
| 164 |
|
| 165 |
-
#
|
|
|
|
|
|
|
|
|
|
| 166 |
return {
|
| 167 |
"code": 200,
|
| 168 |
"message": "success",
|
| 169 |
"data": {
|
| 170 |
"html_report": html_report,
|
| 171 |
-
"sankey_fig": sankey_fig.to_json() if sankey_fig else None, #
|
| 172 |
-
"cluster_fig": cluster_fig.to_json() if cluster_fig else None,
|
| 173 |
"stats": stats
|
| 174 |
}
|
| 175 |
}
|
| 176 |
except Exception as e:
|
|
|
|
| 177 |
return {
|
| 178 |
"code": 500,
|
| 179 |
"message": f"分析失败:{str(e)}",
|
|
|
|
| 140 |
# if __name__ == "__main__":
|
| 141 |
# demo.launch(server_name="0.0.0.0", share=True)
|
| 142 |
|
| 143 |
+
# ================== 大赛平台专用 API(最终修正版)==================
|
| 144 |
+
from fastapi import FastAPI, File, UploadFile, Form
|
| 145 |
import uvicorn
|
| 146 |
from io import BytesIO
|
| 147 |
|
|
|
|
| 154 |
timestamp: str = Form(...), # 平台传递的时间戳
|
| 155 |
signature: str = Form(...) # 平台传递的签名(可选校验)
|
| 156 |
):
|
| 157 |
+
# 修复 1:删除未定义的 rawbody 打印(或注释掉)
|
| 158 |
+
print(f"平台上传的文件名:{file.filename}")
|
| 159 |
+
print(f"平台传递的token:{token}")
|
| 160 |
+
print(f"平台传递的时间戳:{timestamp}")
|
| 161 |
+
|
| 162 |
try:
|
| 163 |
+
# 1. 读取文件内容,转为 BytesIO 内存文件
|
| 164 |
excel_content = await file.read()
|
| 165 |
+
excel_file = BytesIO(excel_content)
|
| 166 |
|
| 167 |
+
# 2. 调用 analyze_report(传递内存文件,内部会自动适配)
|
| 168 |
+
html_report, sankey_fig, cluster_fig, stats = analyze_report(excel_file)
|
| 169 |
+
|
| 170 |
+
# 3. 按平台要求返回JSON(Plotly 图直接调用 to_json())
|
| 171 |
return {
|
| 172 |
"code": 200,
|
| 173 |
"message": "success",
|
| 174 |
"data": {
|
| 175 |
"html_report": html_report,
|
| 176 |
+
"sankey_fig": sankey_fig.to_json() if sankey_fig is not None else None, # Plotly 支持 to_json()
|
| 177 |
+
"cluster_fig": cluster_fig.to_json() if cluster_fig is not None else None,
|
| 178 |
"stats": stats
|
| 179 |
}
|
| 180 |
}
|
| 181 |
except Exception as e:
|
| 182 |
+
print(f"接口报错详情:{str(e)}")
|
| 183 |
return {
|
| 184 |
"code": 500,
|
| 185 |
"message": f"分析失败:{str(e)}",
|