Spaces:
Running on Zero
Running on Zero
Download app/services/ingest.py from cipher-attacks/Dbu-central-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/cipher-attacks/Dbu-central-bot/resolve/main/app/services/ingest.py
- Command line
-
hf download hf://spaces/cipher-attacks/Dbu-central-bot/app/services/ingest.py
-
curl -L -o ingest.py https://huggingface.co/spaces/cipher-attacks/Dbu-central-bot/resolve/main/app/services/ingest.py
1.23 kB
| """Admin upload caption parsing: <course_id> <kind> [title...] e.g. 12 exam Midterm 2017""" | |
| from typing import Optional | |
| KIND_ALIASES = { | |
| "slide": "slide", "slides": "slide", "ppt": "slide", | |
| "exam": "exam", "exams": "exam", "test": "exam", | |
| "note": "note", "notes": "note", "module": "note", | |
| "book": "book", "books": "book", | |
| } | |
| def parse_caption(caption: Optional[str]) -> Optional[tuple[int, str, Optional[str]]]: | |
| if not caption: | |
| return None | |
| parts = caption.strip().split(maxsplit=2) | |
| if len(parts) < 2 or not parts[0].isdigit(): | |
| return None | |
| kind = KIND_ALIASES.get(parts[1].lower().lstrip("#")) | |
| if not kind: | |
| return None | |
| title = parts[2].strip() if len(parts) == 3 and parts[2].strip() else None | |
| return int(parts[0]), kind, title | |
| def clean_title(file_name: Optional[str], caption: Optional[str], fallback: str) -> str: | |
| """Readable title for bulk uploads: file name without extension, else first caption line.""" | |
| import os | |
| name = os.path.splitext(file_name)[0] if file_name else "" | |
| name = name.replace("_", " ").strip() | |
| if not name and caption: | |
| name = caption.strip().split("\n")[0].strip() | |
| return (name or fallback)[:250] | |