Spaces:
Sleeping
Sleeping
Update syllabus_utils.py
Browse files- syllabus_utils.py +25 -1
syllabus_utils.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# syllabus_utils.py
|
| 2 |
"""
|
| 3 |
工具函数:
|
| 4 |
-
- 解析 Syllabus(.docx / .pdf)
|
| 5 |
- 提取课程大纲 topics
|
| 6 |
"""
|
| 7 |
|
|
@@ -56,6 +56,30 @@ def parse_syllabus_pdf(path: str) -> List[str]:
|
|
| 56 |
return chunks[: len(DEFAULT_COURSE_TOPICS)] or DEFAULT_COURSE_TOPICS
|
| 57 |
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def extract_course_topics_from_file(file_obj, doc_type: str) -> List[str]:
|
| 60 |
"""
|
| 61 |
根据上传文件和 doc_type 提取课程大纲 topics。
|
|
|
|
| 1 |
# syllabus_utils.py
|
| 2 |
"""
|
| 3 |
工具函数:
|
| 4 |
+
- 解析 Syllabus(.docx / .pdf/ .pptx)
|
| 5 |
- 提取课程大纲 topics
|
| 6 |
"""
|
| 7 |
|
|
|
|
| 56 |
return chunks[: len(DEFAULT_COURSE_TOPICS)] or DEFAULT_COURSE_TOPICS
|
| 57 |
|
| 58 |
|
| 59 |
+
from pptx import Presentation # python-pptx
|
| 60 |
+
|
| 61 |
+
def parse_pptx_slides(path: str) -> List[str]:
|
| 62 |
+
"""
|
| 63 |
+
从 .pptx 文件中抽取每一页 slide 的文本,返回一个字符串列表。
|
| 64 |
+
- 每一页作为一个文本块(RAG 的一个 chunk)
|
| 65 |
+
- 只收集有文字的 shape
|
| 66 |
+
"""
|
| 67 |
+
prs = Presentation(path)
|
| 68 |
+
slide_texts: List[str] = []
|
| 69 |
+
|
| 70 |
+
for slide in prs.slides:
|
| 71 |
+
lines: List[str] = []
|
| 72 |
+
for shape in slide.shapes:
|
| 73 |
+
if hasattr(shape, "text") and shape.text:
|
| 74 |
+
txt = shape.text.strip()
|
| 75 |
+
if txt:
|
| 76 |
+
lines.append(txt)
|
| 77 |
+
if lines:
|
| 78 |
+
slide_texts.append("\n".join(lines))
|
| 79 |
+
|
| 80 |
+
return slide_texts
|
| 81 |
+
|
| 82 |
+
|
| 83 |
def extract_course_topics_from_file(file_obj, doc_type: str) -> List[str]:
|
| 84 |
"""
|
| 85 |
根据上传文件和 doc_type 提取课程大纲 topics。
|