Spaces:
Running
Running
added code
Browse files
app.py
CHANGED
|
@@ -1,59 +1,53 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from utils import load_json, count_tokens
|
| 3 |
import json
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
st.write(x, "squared is", x * x)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
with open(file_path, "r") as file:
|
| 22 |
code_content = file.read()
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
st.
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
st.success(
|
| 47 |
-
f"Code has been chunked with a target of {token_chunk_size} tokens per chunk."
|
| 48 |
-
)
|
| 49 |
-
# Displaying the chunked code - this would be replaced with actual chunked code display logic
|
| 50 |
-
st.text_area(
|
| 51 |
-
"Chunked Code",
|
| 52 |
-
value="Chunked code would appear here...",
|
| 53 |
-
height=250,
|
| 54 |
-
max_chars=50000,
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if __name__ == "__main__":
|
| 59 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
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)
|
| 11 |
|
| 12 |
+
# Setup Streamlit page
|
| 13 |
+
st.set_page_config(page_title="Cintra Code Chunker", layout="wide")
|
|
|
|
| 14 |
|
| 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 |
+
code_files = code_files_data['files']
|
| 19 |
|
| 20 |
+
# UI Elements
|
| 21 |
+
st.title('Cintra Code Chunker')
|
| 22 |
|
| 23 |
+
# File selection
|
| 24 |
+
selected_file_name = st.selectbox("Select a code file", code_files)
|
| 25 |
|
| 26 |
+
# Assuming you have the path or the content in the JSON, adjust accordingly
|
| 27 |
+
# This example assumes paths are stored in the JSON
|
| 28 |
+
file_path = os.path.join(os.path.dirname(__file__), 'example_code_files', selected_file_name)
|
| 29 |
with open(file_path, "r") as file:
|
| 30 |
code_content = file.read()
|
| 31 |
+
|
| 32 |
+
col1, col2 = st.columns(2)
|
| 33 |
+
|
| 34 |
+
with col1:
|
| 35 |
+
st.subheader('Original File')
|
| 36 |
+
st.code(code_content, language='python') # Adjust language dynamically based on file extension if necessary
|
| 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, assuming it takes file extension and encoding name
|
| 42 |
+
file_extension = selected_file_name.split('.')[-1]
|
| 43 |
+
code_chunker = CodeChunker(file_extension=file_extension)
|
| 44 |
+
|
| 45 |
+
# Chunk the code content
|
| 46 |
+
chunked_code_dict = code_chunker.chunk(code_content, token_chunk_size)
|
| 47 |
+
|
| 48 |
+
# Select a chunk to display
|
| 49 |
+
chunk_keys = list(chunked_code_dict.keys())
|
| 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='python') # Adjust language dynamically based on file extension if necessary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|