Spaces:
Running
Running
added setuptools==69.2.0
Browse files- __pycache__/Chunker.cpython-312.pyc +0 -0
- __pycache__/CodeParser.cpython-312.pyc +0 -0
- __pycache__/utils.cpython-312.pyc +0 -0
- app.py +24 -12
- requirements.txt +1 -0
__pycache__/Chunker.cpython-312.pyc
ADDED
Binary file (4.87 kB). View file
|
|
__pycache__/CodeParser.cpython-312.pyc
ADDED
Binary file (11.6 kB). View file
|
|
__pycache__/utils.cpython-312.pyc
ADDED
Binary file (901 Bytes). View file
|
|
app.py
CHANGED
@@ -3,8 +3,7 @@ import json
|
|
3 |
import os
|
4 |
from Chunker import CodeChunker
|
5 |
from utils import count_tokens
|
6 |
-
|
7 |
-
# Load JSON data for code file paths
|
8 |
def load_json_file(file_path):
|
9 |
with open(file_path, 'r') as file:
|
10 |
return json.load(file)
|
@@ -15,7 +14,9 @@ st.set_page_config(page_title="Cintra Code Chunker", layout="wide")
|
|
15 |
# Assuming app.py and mock_codefiles.json are in the same directory
|
16 |
json_file_path = os.path.join(os.path.dirname(__file__), 'mock_codefiles.json')
|
17 |
code_files_data = load_json_file(json_file_path)
|
18 |
-
|
|
|
|
|
19 |
|
20 |
# UI Elements
|
21 |
st.title('Cintra Code Chunker')
|
@@ -23,23 +24,34 @@ st.title('Cintra Code Chunker')
|
|
23 |
# File selection
|
24 |
selected_file_name = st.selectbox("Select a code file", code_files)
|
25 |
|
26 |
-
# Assuming you have the
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
col1, col2 = st.columns(2)
|
33 |
|
34 |
with col1:
|
35 |
st.subheader('Original File')
|
36 |
-
st.code(code_content, language=
|
37 |
|
38 |
with col2:
|
39 |
token_chunk_size = st.sidebar.slider('Token Chunk Size Target', min_value=5, max_value=50, value=25)
|
40 |
if st.sidebar.button("Chunk Code"):
|
41 |
-
# Initialize the code chunker
|
42 |
-
file_extension = selected_file_name.split('.')[-1]
|
43 |
code_chunker = CodeChunker(file_extension=file_extension)
|
44 |
|
45 |
# Chunk the code content
|
@@ -50,4 +62,4 @@ with col2:
|
|
50 |
selected_chunk_key = st.selectbox("Select Chunk", options=chunk_keys)
|
51 |
|
52 |
st.subheader('Chunked Code')
|
53 |
-
st.code(chunked_code_dict[selected_chunk_key], language=
|
|
|
3 |
import os
|
4 |
from Chunker import CodeChunker
|
5 |
from utils import count_tokens
|
6 |
+
# Function to load JSON data
|
|
|
7 |
def load_json_file(file_path):
|
8 |
with open(file_path, 'r') as file:
|
9 |
return json.load(file)
|
|
|
14 |
# Assuming app.py and mock_codefiles.json are in the same directory
|
15 |
json_file_path = os.path.join(os.path.dirname(__file__), 'mock_codefiles.json')
|
16 |
code_files_data = load_json_file(json_file_path)
|
17 |
+
|
18 |
+
# Extract filenames and contents
|
19 |
+
code_files = list(code_files_data.keys())
|
20 |
|
21 |
# UI Elements
|
22 |
st.title('Cintra Code Chunker')
|
|
|
24 |
# File selection
|
25 |
selected_file_name = st.selectbox("Select a code file", code_files)
|
26 |
|
27 |
+
# Assuming you have the content as a string in the JSON, extract directly
|
28 |
+
code_content = code_files_data[selected_file_name]
|
29 |
+
|
30 |
+
file_extension = selected_file_name.split('.')[-1]
|
31 |
+
|
32 |
+
# Determine the language for syntax highlighting
|
33 |
+
def get_language_by_extension(file_extension):
|
34 |
+
if file_extension in ['py', 'python']:
|
35 |
+
return 'python'
|
36 |
+
elif file_extension in ['js', 'jsx', 'javascript']:
|
37 |
+
return 'javascript'
|
38 |
+
elif file_extension == 'css':
|
39 |
+
return 'css'
|
40 |
+
else:
|
41 |
+
return None # Default to no syntax highlighting if extension is not recognized
|
42 |
+
|
43 |
+
language = get_language_by_extension(file_extension)
|
44 |
|
45 |
col1, col2 = st.columns(2)
|
46 |
|
47 |
with col1:
|
48 |
st.subheader('Original File')
|
49 |
+
st.code(code_content, language=language)
|
50 |
|
51 |
with col2:
|
52 |
token_chunk_size = st.sidebar.slider('Token Chunk Size Target', min_value=5, max_value=50, value=25)
|
53 |
if st.sidebar.button("Chunk Code"):
|
54 |
+
# Initialize the code chunker
|
|
|
55 |
code_chunker = CodeChunker(file_extension=file_extension)
|
56 |
|
57 |
# Chunk the code content
|
|
|
62 |
selected_chunk_key = st.selectbox("Select Chunk", options=chunk_keys)
|
63 |
|
64 |
st.subheader('Chunked Code')
|
65 |
+
st.code(chunked_code_dict[selected_chunk_key], language=language)
|
requirements.txt
CHANGED
@@ -43,3 +43,4 @@ typing_extensions==4.11.0
|
|
43 |
tzdata==2024.1
|
44 |
urllib3==2.2.1
|
45 |
watchdog==4.0.0
|
|
|
|
43 |
tzdata==2024.1
|
44 |
urllib3==2.2.1
|
45 |
watchdog==4.0.0
|
46 |
+
setuptools==69.2.0
|