defextract_pdf_text(pdf_file): """提取PDF文本""" with tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) as f: f.write(pdf_file.read()) temp_path = f.name text = office.pdf.read_pdf(temp_path) os.unlink(temp_path) return text
if uploaded_file and book_title and st.button("生成笔记"): with st.spinner("AI正在阅读并生成笔记..."): text = extract_pdf_text(uploaded_file) notes = generate_notes(text, book_title) st.success("笔记生成完成!") st.markdown(notes) # 导出Word if st.button("导出为Word"): output_file = f"{book_title}读书笔记.docx" office.word.create_word(notes, output_file) st.success(f"已导出:{output_file}")