CintraAI commited on
Commit
19c8428
·
1 Parent(s): 1946062

added contribute to github button

Browse files
Files changed (1) hide show
  1. app.py +13 -22
app.py CHANGED
@@ -3,6 +3,9 @@ import json
3
  import os
4
  from Chunker import CodeChunker
5
 
 
 
 
6
  # Function to load JSON data
7
  def load_json_file(file_path):
8
  with open(file_path, 'r') as file:
@@ -12,34 +15,24 @@ def load_json_file(file_path):
12
  def read_code_from_file(uploaded_file):
13
  return uploaded_file.getvalue().decode("utf-8")
14
 
15
- col1, col2 = st.columns(2)
16
-
17
- with col1:
18
- # Setup Streamlit page
19
- st.set_page_config(page_title="Cintra Code Chunker", layout="wide")
20
- with col2:
21
- st.markdown('Interested in contributing? Check out our [GitHub repository](https://github.com/CintraAI/code-chunker) and help us improve!', unsafe_allow_html=True)
22
 
23
- # Assuming app.py and mock_codefiles.json are in the same directory
24
  json_file_path = os.path.join(os.path.dirname(__file__), 'mock_codefiles.json')
25
  code_files_data = load_json_file(json_file_path)
26
 
27
  # Extract filenames and contents
28
  code_files = list(code_files_data.keys())
29
 
30
- # UI Elements
31
  st.title('Cintra Code Chunker')
32
 
33
- # Create two columns for file selection and file upload
34
- col1, col2 = st.columns(2)
35
-
36
- with col1:
37
  # File selection dropdown
38
  selected_file_name = st.selectbox("Select an example code file", code_files)
39
 
40
- with col2:
41
  # File upload
42
- uploaded_file = st.file_uploader("Or upload your code file", type=['py', 'js', 'css'])
43
 
44
  # Determine the content and file extension based on selection or upload
45
  if uploaded_file is not None:
@@ -58,16 +51,15 @@ def get_language_by_extension(file_extension):
58
  elif file_extension == 'css':
59
  return 'css'
60
  else:
61
- return None # Default to no syntax highlighting if extension is not recognized
62
 
63
  language = get_language_by_extension(file_extension)
64
 
65
- # User input for Token Chunk Size
66
- token_chunk_size = st.number_input('Chunk Size Target Measured in Tokens (Using Tiktoken)', min_value=5, max_value=1000, value=25)
67
 
68
- col1, col2 = st.columns(2)
69
 
70
- with col1:
71
  st.subheader('Original File')
72
  st.code(code_content, language=language)
73
 
@@ -77,8 +69,7 @@ code_chunker = CodeChunker(file_extension=file_extension)
77
  # Chunk the code content
78
  chunked_code_dict = code_chunker.chunk(code_content, token_chunk_size)
79
 
80
- # Automatically display chunks without needing to select
81
- with col2:
82
  st.subheader('Chunked Code')
83
  for chunk_key, chunk_code in chunked_code_dict.items():
84
  st.code(chunk_code, language=language)
 
3
  import os
4
  from Chunker import CodeChunker
5
 
6
+ # Set Streamlit page config at the very beginning
7
+ st.set_page_config(page_title="Cintra Code Chunker", layout="wide")
8
+
9
  # Function to load JSON data
10
  def load_json_file(file_path):
11
  with open(file_path, 'r') as file:
 
15
  def read_code_from_file(uploaded_file):
16
  return uploaded_file.getvalue().decode("utf-8")
17
 
18
+ st.link_button('Contribute on GitHub', 'https://github.com/CintraAI/code-chunker', help=None, type="secondary", disabled=False, use_container_width=False)
 
 
 
 
 
 
19
 
 
20
  json_file_path = os.path.join(os.path.dirname(__file__), 'mock_codefiles.json')
21
  code_files_data = load_json_file(json_file_path)
22
 
23
  # Extract filenames and contents
24
  code_files = list(code_files_data.keys())
25
 
 
26
  st.title('Cintra Code Chunker')
27
 
28
+ selection_col, upload_col = st.columns(2)
29
+ with selection_col:
 
 
30
  # File selection dropdown
31
  selected_file_name = st.selectbox("Select an example code file", code_files)
32
 
33
+ with upload_col:
34
  # File upload
35
+ uploaded_file = st.file_uploader("Or upload your code file", type=['py', 'js', 'css', 'jsx'])
36
 
37
  # Determine the content and file extension based on selection or upload
38
  if uploaded_file is not None:
 
51
  elif file_extension == 'css':
52
  return 'css'
53
  else:
54
+ return None
55
 
56
  language = get_language_by_extension(file_extension)
57
 
58
+ token_chunk_size = st.number_input('Chunk Size Target Measured in Tokens (tiktoken, gpt-4)', min_value=5, max_value=1000, value=25)
 
59
 
60
+ original_col, chunked_col = st.columns(2)
61
 
62
+ with original_col:
63
  st.subheader('Original File')
64
  st.code(code_content, language=language)
65
 
 
69
  # Chunk the code content
70
  chunked_code_dict = code_chunker.chunk(code_content, token_chunk_size)
71
 
72
+ with chunked_col:
 
73
  st.subheader('Chunked Code')
74
  for chunk_key, chunk_code in chunked_code_dict.items():
75
  st.code(chunk_code, language=language)