Spaces:
Sleeping
Sleeping
added setuptools==69.2.0
Browse filesFiles changed (5)
2 unmodified lines3456789104 unmodified lines151617181920211 unmodified line23242526272829303132333435363738394041424344454 unmodified lines505152532 unmodified linesimport osfrom Chunker import CodeChunkerfrom utils import count_tokens# Load JSON data for code file pathsdef load_json_file(file_path):with open(file_path, 'r') as file:return json.load(file)4 unmodified lines# Assuming app.py and mock_codefiles.json are in the same directoryjson_file_path = os.path.join(os.path.dirname(__file__), 'mock_codefiles.json')code_files_data = load_json_file(json_file_path)code_files = code_files_data['files']# UI Elementsst.title('Cintra Code Chunker')1 unmodified line# File selectionselected_file_name = st.selectbox("Select a code file", code_files)# Assuming you have the path or the content in the JSON, adjust accordingly# This example assumes paths are stored in the JSONfile_path = os.path.join(os.path.dirname(__file__), 'example_code_files', selected_file_name)with open(file_path, "r") as file:code_content = file.read()col1, col2 = st.columns(2)with col1:st.subheader('Original File')st.code(code_content, language='python') # Adjust language dynamically based on file extension if necessarywith col2:token_chunk_size = st.sidebar.slider('Token Chunk Size Target', min_value=5, max_value=50, value=25)if st.sidebar.button("Chunk Code"):# Initialize the code chunker, assuming it takes file extension and encoding namefile_extension = selected_file_name.split('.')[-1]code_chunker = CodeChunker(file_extension=file_extension)# Chunk the code content4 unmodified linesselected_chunk_key = st.selectbox("Select Chunk", options=chunk_keys)st.subheader('Chunked Code')st.code(chunked_code_dict[selected_chunk_key], language='python') # Adjust language dynamically based on file extension if necessary2 unmodified lines34567894 unmodified lines1415161718192021221 unmodified line242526272829303132333435363738394041424344454647484950515253545556574 unmodified lines626364652 unmodified linesimport osfrom Chunker import CodeChunkerfrom utils import count_tokens# Function to load JSON datadef load_json_file(file_path):with open(file_path, 'r') as file:return json.load(file)4 unmodified lines# Assuming app.py and mock_codefiles.json are in the same directoryjson_file_path = os.path.join(os.path.dirname(__file__), 'mock_codefiles.json')code_files_data = load_json_file(json_file_path)# Extract filenames and contentscode_files = list(code_files_data.keys())# UI Elementsst.title('Cintra Code Chunker')1 unmodified line# File selectionselected_file_name = st.selectbox("Select a code file", code_files)# Assuming you have the content as a string in the JSON, extract directlycode_content = code_files_data[selected_file_name]file_extension = selected_file_name.split('.')[-1]# Determine the language for syntax highlightingdef get_language_by_extension(file_extension):if file_extension in ['py', 'python']:return 'python'elif file_extension in ['js', 'jsx', 'javascript']:return 'javascript'elif file_extension == 'css':return 'css'else:return None # Default to no syntax highlighting if extension is not recognizedlanguage = get_language_by_extension(file_extension)col1, col2 = st.columns(2)with col1:st.subheader('Original File')st.code(code_content, language=language)with col2:token_chunk_size = st.sidebar.slider('Token Chunk Size Target', min_value=5, max_value=50, value=25)if st.sidebar.button("Chunk Code"):# Initialize the code chunkercode_chunker = CodeChunker(file_extension=file_extension)# Chunk the code content4 unmodified linesselected_chunk_key = st.selectbox("Select Chunk", options=chunk_keys)st.subheader('Chunked Code')st.code(chunked_code_dict[selected_chunk_key], language=language)
42 unmodified lines43444542 unmodified linestzdata==2024.1urllib3==2.2.1watchdog==4.0.042 unmodified lines4344454642 unmodified linestzdata==2024.1urllib3==2.2.1watchdog==4.0.0setuptools==69.2.0
__pycache__/Chunker.cpython-312.pycAdded
__pycache__/CodeParser.cpython-312.pycAdded
__pycache__/utils.cpython-312.pycAdded
app.py+24-12
requirements.txt+1