github star gitee star atomgit star PyPI Downloads AI编程 AI交流群

大家好,这里是程序员晚枫,正在all in AI编程实战

第28讲:完整项目实战——从0到1做一个AI产品

项目目标:做一个"AI读书笔记助手"

功能:

  • 上传PDF书籍
  • AI自动提取重点
  • 生成读书笔记
  • 一键导出Word

1、确定技术栈

1
2
3
4
前端:Streamlit(快速开发)
AI:DeepSeek(便宜好用)
文件处理:python-office
部署:Streamlit Cloud(免费)

2、创建项目结构

1
2
3
4
5
6
ai-book-notes/
├── app.py # 主应用
├── requirements.txt # 依赖
├── README.md # 说明文档
└── .streamlit/
└── config.toml # Streamlit配置

3、主应用代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# app.py
import streamlit as st
from openai import OpenAI
import office
import tempfile
import os

st.set_page_config(
page_title="AI读书笔记助手",
page_icon="📚"
)

st.title("📚 AI读书笔记助手")

client = OpenAI(api_key="你的Key", base_url="https://api.deepseek.com")

def extract_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

def generate_notes(text, book_title):
"""AI生成读书笔记"""
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{
"role": "user",
"content": f"""你是一个读书笔记专家。请为以下书籍生成详细的读书笔记。

书籍:《{book_title}

要求笔记包含:
1. 书籍简介(100字)
2. 核心观点(3-5个)
3. 精彩摘录(5段)
4. 个人感悟(200字)
5. 行动清单(3条)

书籍内容:
{text[:5000]}"""
}]
)
return response.choices[0].message.content

# 上传PDF
uploaded_file = st.file_uploader("上传PDF书籍", type=["pdf"])

book_title = st.text_input("书籍名称", placeholder="例如:Python编程从入门到实践")

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}")

4、配置文件

1
2
3
4
5
6
7
8
9
10
# .streamlit/config.toml
[theme]
primaryColor = "#1f77b4"
backgroundColor = "#ffffff"
secondaryBackgroundColor = "#f0f2f6"
textColor = "#262730"
font = "sans serif"

[server]
headless = true

5、依赖文件

1
2
3
streamlit
openai
python-office

6、本地运行

1
streamlit run app.py

浏览器打开 http://localhost:8501 即可使用。

7、部署上线

1
2
3
4
5
6
7
8
# 推送到GitHub
git init
git add .
git commit -m "AI读书笔记助手 v1.0"
git remote add origin https://github.com/你的用户名/ai-book-notes.git
git push -u origin main

# 然后去 Streamlit Cloud 点击 Deploy

8、优化建议

功能优化方向
速度分段处理PDF
准确性添加prompt模板
体验添加进度条
变现添加付费功能

下讲预告

学会了完整项目,下一讲我们学 AI编程的未来——趋势和机会。

敬请期待!


程序员晚枫专注AI编程培训,小白看完他和图灵社区合作的教程《30讲 · AI编程训练营》就能上手做AI项目。

前3讲可以试听,试听链接:https://www.bilibili.com/cheese/play/ss982042944