Spaces:
Sleeping
Sleeping
File size: 2,555 Bytes
2f386cc 85d744c 2f386cc 85d744c 2f386cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import logging
import os
from openai import OpenAI
import repo
import streamlit as st
from streamlit_tree_select import tree_select
from utils import EXTENSION_TO_LANGUAGE_MAP
class RepoForm:
"""A class to encapsulate the repository form and its operations."""
options = EXTENSION_TO_LANGUAGE_MAP.keys()
def __init__(self, default_repo_url: str):
self.default_repo_url = default_repo_url
self.repo_url = ""
self.api_key = ""
self.extensions = []
self.additional_extensions = ""
def display_form(self):
"""Displays the repository form and its elements."""
self.repo_url = st.text_input(
"GitHub Repository URL:", self.default_repo_url
)
self.extensions = st.multiselect(
"File extensions to analyze",
options=self.options,
default=self.options,
)
self.additional_extensions = st.text_input(
"Additional file extensions to analyze (comma-separated):"
)
if self.additional_extensions:
self.extensions.extend(
[ext.strip() for ext in self.additional_extensions.split(",")]
)
self.clone_repo_button = st.form_submit_button("Clone Repository")
def get_form_data(self):
"""Returns the data captured by the repository form."""
return (
self.repo_url,
self.extensions,
)
def is_api_key_valid(self):
"""Checks if the OpenAI API key is valid and returns a boolean value."""
if not self.api_key:
st.error("Please enter your OpenAI API key.")
return False
return True
class AnalyzeFilesForm:
"""A class to encapsulate the analyze files form and its operations."""
def __init__(self, session_state):
self.session_state = session_state
def display_form(self):
"""Displays the analyze files form and its elements."""
st.write("Select files to analyze:")
file_tree = repo.create_file_tree(self.session_state.code_files)
self.session_state.selected_files = tree_select(
file_tree,
show_expand_all=True,
check_model="leaf",
checked=self.session_state.get("selected_files"),
)["checked"]
logging.info("Selected files: %s", self.session_state.selected_files)
self.session_state.analyze_files = st.form_submit_button(
"Analyze Files"
) or self.session_state.get("analyze_files")
|