CoolFace
Apppublic

irshadtech10/Repo_Analyzer

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
display.py54 linesDownload Raw Back to root
1import re2from typing import Optional3 4import streamlit as st5from utils import EXTENSION_TO_LANGUAGE_MAP6 7 8def extension_to_language(file_extension: str) -> Optional[str]:9    """Return the programming language corresponding to a given file extension."""10    return EXTENSION_TO_LANGUAGE_MAP.get(file_extension.lower(), None)11 12 13def display_code(code: str, extension: str) -> None:14    """Display the code snippet in the specified language."""15    language = extension_to_language(extension)16    markdown_code = f"```{language}\n{code}\n```"17    st.markdown(markdown_code)18 19 20def escape_markdown(text: str) -> str:21    """Escape markdown characters in a string."""22    escape_chars = [23        "\\",24        "`",25        "*",26        "_",27        "{",28        "}",29        "[",30        "]",31        "(",32        ")",33        "#",34        "+",35        "-",36        ".",37        "!",38    ]39    regex = re.compile("|".join(map(re.escape, escape_chars)))40    return regex.sub(r"\\\g<0>", text)41 42 43def generate_markdown(recommendations):44    markdown_str = "# ChatGPT Code Review Recommendations\n\n"45 46    for rec in recommendations:47        code_file = rec["code_file"]48        recommendation = rec["recommendation"] or "No recommendations"49 50        markdown_str += f"## {code_file}\n\n"51        markdown_str += f"{recommendation}\n\n"52 53    return markdown_str54