Download parse_feedback.py from build-small-hackathon/patient-virtuel-dentiste: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/build-small-hackathon/patient-virtuel-dentiste/resolve/b05542b6cc08dc3eaa013120cc6ab932aedd31af/parse_feedback.py
- Command line
-
hf download hf://spaces/build-small-hackathon/patient-virtuel-dentiste@b05542b6cc08dc3eaa013120cc6ab932aedd31af/parse_feedback.py
-
curl -L -o parse_feedback.py https://huggingface.co/spaces/build-small-hackathon/patient-virtuel-dentiste/resolve/b05542b6cc08dc3eaa013120cc6ab932aedd31af/parse_feedback.py
1.01 kB
| import re | |
| PATTERN = re.compile( | |
| r"Disse:\s*(.+?)\s*Correction:\s*(.+?)\s*Explication:\s*(.+?)(?=\s*Disse:|\s*$)", | |
| re.DOTALL | re.IGNORECASE, | |
| ) | |
| def parse_feedback(text: str) -> list[dict]: | |
| entries = [] | |
| for m in PATTERN.finditer(text): | |
| entries.append({ | |
| "disse": m.group(1).strip(), | |
| "correction": m.group(2).strip(), | |
| "explication": m.group(3).strip(), | |
| }) | |
| return entries | |
| def render_feedback_table(entries: list[dict]) -> list[list[str]]: | |
| return [[e["disse"], e["correction"], e["explication"]] for e in entries] | |
| def strip_markdown(text: str) -> str: | |
| text = re.sub(r"\*\*(.+?)\*\*", r"\1", text) | |
| text = re.sub(r"\*(.+?)\*", r"\1", text) | |
| text = re.sub(r"`(.+?)`", r"\1", text) | |
| text = re.sub(r"#{1,6}\s*", "", text) | |
| text = re.sub(r"^[-*]\s", "", text, flags=re.MULTILINE) | |
| text = re.sub(r"!?\[.*?\]\(.*?\)", "", text) | |
| text = text.replace("▌", "") | |
| text = text.replace("🤖", "") | |
| return text.strip() | |