Team Ai
Apppublic

typicaleoxx/code-explainer-ai

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
parser.py46 linesDownload Raw Back to root
1import re2 3 4def clean_markdown(text):5    # remove markdown headings6    text = re.sub(r"^#{1,6}\s*", "", text, flags=re.MULTILINE)7 8    # remove stray triple quotes9    text = text.replace('"""', "")10 11    # remove bold markers12    text = text.replace("**", "")13 14    return text15 16 17def parse_analysis(text):18 19    sections = {20        "Code Summary": "",21        "Logic Explanation": "",22        "Execution Walkthrough": "",23        "Code Quality Issues": "",24        "Performance Analysis": "",25        "Security Concerns": "",26        "Improved Version": "",27    }28 29    current_section = None30 31    for line in text.split("\n"):32 33        for section in sections.keys():34            if section.lower() in line.lower():35                current_section = section36                continue37 38        if current_section:39            sections[current_section] += line + "\n"40 41    # clean formatting42    for key in sections:43        sections[key] = clean_markdown(sections[key]).strip()44 45    return sections46