CoolFace
Apppublic

irshadtech10/Repo_Analyzer

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
forms.py79 linesDownload Raw Back to root
1import logging2import os3 4from openai import OpenAI5import repo6import streamlit as st7from streamlit_tree_select import tree_select8from utils import EXTENSION_TO_LANGUAGE_MAP9 10 11class RepoForm:12    """A class to encapsulate the repository form and its operations."""13 14    options = EXTENSION_TO_LANGUAGE_MAP.keys()15 16    def __init__(self, default_repo_url: str):17        self.default_repo_url = default_repo_url18        self.repo_url = ""19        self.api_key = ""20        self.extensions = []21        self.additional_extensions = ""22 23    def display_form(self):24        """Displays the repository form and its elements."""25        self.repo_url = st.text_input(26            "GitHub Repository URL:", self.default_repo_url27        )28        29        self.extensions = st.multiselect(30            "File extensions to analyze",31            options=self.options,32            default=self.options,33        )34        self.additional_extensions = st.text_input(35            "Additional file extensions to analyze (comma-separated):"36        )37        if self.additional_extensions:38            self.extensions.extend(39                [ext.strip() for ext in self.additional_extensions.split(",")]40            )41 42        self.clone_repo_button = st.form_submit_button("Clone Repository")43 44    def get_form_data(self):45        """Returns the data captured by the repository form."""46        return (47            self.repo_url,48            self.extensions,49        )50 51    def is_api_key_valid(self):52        """Checks if the OpenAI API key is valid and returns a boolean value."""53        if not self.api_key:54            st.error("Please enter your OpenAI API key.")55            return False56        return True57 58 59class AnalyzeFilesForm:60    """A class to encapsulate the analyze files form and its operations."""61 62    def __init__(self, session_state):63        self.session_state = session_state64 65    def display_form(self):66        """Displays the analyze files form and its elements."""67        st.write("Select files to analyze:")68        file_tree = repo.create_file_tree(self.session_state.code_files)69        self.session_state.selected_files = tree_select(70            file_tree,71            show_expand_all=True,72            check_model="leaf",73            checked=self.session_state.get("selected_files"),74        )["checked"]75        logging.info("Selected files: %s", self.session_state.selected_files)76        self.session_state.analyze_files = st.form_submit_button(77            "Analyze Files"78        ) or self.session_state.get("analyze_files")79