Spaces:
Sleeping
Sleeping
Update api/syllabus_utils.py
Browse files- api/syllabus_utils.py +6 -4
api/syllabus_utils.py
CHANGED
|
@@ -15,6 +15,8 @@ from pypdf import PdfReader
|
|
| 15 |
from pptx import Presentation # python-pptx
|
| 16 |
|
| 17 |
from api.config import DEFAULT_COURSE_TOPICS
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def parse_syllabus_docx(path: str) -> List[str]:
|
|
@@ -74,7 +76,6 @@ def parse_pptx_slides(path: str) -> List[str]:
|
|
| 74 |
return slide_texts
|
| 75 |
|
| 76 |
|
| 77 |
-
|
| 78 |
def extract_course_topics_from_file(file_obj, doc_type: str) -> List[str]:
|
| 79 |
"""
|
| 80 |
根据上传文件和 doc_type 提取课程大纲 topics。
|
|
@@ -84,10 +85,12 @@ def extract_course_topics_from_file(file_obj, doc_type: str) -> List[str]:
|
|
| 84 |
if file_obj is None:
|
| 85 |
return DEFAULT_COURSE_TOPICS
|
| 86 |
|
| 87 |
-
|
|
|
|
| 88 |
return DEFAULT_COURSE_TOPICS
|
| 89 |
|
| 90 |
-
|
|
|
|
| 91 |
if not file_path:
|
| 92 |
return DEFAULT_COURSE_TOPICS
|
| 93 |
|
|
@@ -99,7 +102,6 @@ def extract_course_topics_from_file(file_obj, doc_type: str) -> List[str]:
|
|
| 99 |
elif ext == ".pdf":
|
| 100 |
topics = parse_syllabus_pdf(file_path)
|
| 101 |
elif ext == ".pptx":
|
| 102 |
-
# pptx 直接用 slides 文本作为 topics(也可以后续再做 “Week/Module” 提取)
|
| 103 |
topics = parse_pptx_slides(file_path)
|
| 104 |
else:
|
| 105 |
print(f"[Syllabus] Unsupported file type for syllabus: {ext}")
|
|
|
|
| 15 |
from pptx import Presentation # python-pptx
|
| 16 |
|
| 17 |
from api.config import DEFAULT_COURSE_TOPICS
|
| 18 |
+
from api.some_module import parse_syllabus_docx, parse_syllabus_pdf, parse_pptx_slides
|
| 19 |
+
|
| 20 |
|
| 21 |
|
| 22 |
def parse_syllabus_docx(path: str) -> List[str]:
|
|
|
|
| 76 |
return slide_texts
|
| 77 |
|
| 78 |
|
|
|
|
| 79 |
def extract_course_topics_from_file(file_obj, doc_type: str) -> List[str]:
|
| 80 |
"""
|
| 81 |
根据上传文件和 doc_type 提取课程大纲 topics。
|
|
|
|
| 85 |
if file_obj is None:
|
| 86 |
return DEFAULT_COURSE_TOPICS
|
| 87 |
|
| 88 |
+
doc_type_norm = (doc_type or "").strip().lower()
|
| 89 |
+
if doc_type_norm != "syllabus":
|
| 90 |
return DEFAULT_COURSE_TOPICS
|
| 91 |
|
| 92 |
+
# 兼容两种:file_obj.name (临时文件路径) / UploadFile.filename(只是名字,不是路径)
|
| 93 |
+
file_path = getattr(file_obj, "name", None) or getattr(file_obj, "filename", None)
|
| 94 |
if not file_path:
|
| 95 |
return DEFAULT_COURSE_TOPICS
|
| 96 |
|
|
|
|
| 102 |
elif ext == ".pdf":
|
| 103 |
topics = parse_syllabus_pdf(file_path)
|
| 104 |
elif ext == ".pptx":
|
|
|
|
| 105 |
topics = parse_pptx_slides(file_path)
|
| 106 |
else:
|
| 107 |
print(f"[Syllabus] Unsupported file type for syllabus: {ext}")
|