Update src/streamlit_app.py
Browse files294 unmodified lines295296297298299300301302303304305306307308309310311312313433 unmodified lines747748749750751752753754755756757758759760761762763764765294 unmodified linesreturn {}finally:# 清理临时文件shutil.rmtree(temp_dir)uploaded_file = st.file_uploader("上传Excel文件(包含ASIN及产品信息的数据表)", type=["xlsx"],help="请上传包含ASIN列的Excel文件,文件应包含产品信息如品牌、价格、销量等数据。系统将自动提取嵌入的产品图片。")if uploaded_file is not None:try:# 使用唯一文件名避免冲突unique_id = str(uuid.uuid4())temp_file = f"temp_upload_{unique_id}.xlsx"# 保存上传的文件到临时位置with open(temp_file, "wb") as f:f.write(uploaded_file.getvalue())# 读取Excel文件433 unmodified linesst.error(f"读取Excel文件时出错: {str(e)}")st.info("请确保上传的Excel文件格式正确且未损坏")finally:# 清理临时文件 - 使用延迟和尝试多次删除try:if os.path.exists(temp_file):try:os.remove(temp_file)except PermissionError:# 如果文件被占用,等待一会儿再尝试time.sleep(1)try:os.remove(temp_file)except:pass # 忽略最终的错误except:pass # 忽略任何清理错误else:st.info("请上传Excel文件以开始提取数据")294 unmodified lines295296297298299300301302303304305306307308309310311312313314315316433 unmodified lines750751752753754755756757758759760294 unmodified linesreturn {}finally:# 清理临时文件try:if 'temp_file' in locals() and os.path.exists(temp_file):os.remove(temp_file)except Exception as e:pass # 忽略任何清理错误uploaded_file = st.file_uploader("上传Excel文件(包含ASIN及产品信息的数据表)", type=["xlsx"],help="请上传包含ASIN列的Excel文件,文件应包含产品信息如品牌、价格、销量等数据。系统将自动提取嵌入的产品图片。")if uploaded_file is not None:try:# 使用临时文件系统创建临时文件temp_fd, temp_file = tempfile.mkstemp(suffix=".xlsx")# 保存上传的文件到临时位置with os.fdopen(temp_fd, "wb") as f:f.write(uploaded_file.getvalue())# 读取Excel文件433 unmodified linesst.error(f"读取Excel文件时出错: {str(e)}")st.info("请确保上传的Excel文件格式正确且未损坏")finally:# 清理临时文件try:if 'temp_file' in locals() and os.path.exists(temp_file):os.remove(temp_file)except Exception as e:pass # 忽略任何清理错误else:st.info("请上传Excel文件以开始提取数据")
src/streamlit_app.py+12-17