Spaces:
Running
Running
put uploader side by side
Browse files
app.py
CHANGED
|
@@ -8,6 +8,10 @@ def load_json_file(file_path):
|
|
| 8 |
with open(file_path, 'r') as file:
|
| 9 |
return json.load(file)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Setup Streamlit page
|
| 12 |
st.set_page_config(page_title="Cintra Code Chunker", layout="wide")
|
| 13 |
|
|
@@ -21,16 +25,24 @@ code_files = list(code_files_data.keys())
|
|
| 21 |
# UI Elements
|
| 22 |
st.title('Cintra Code Chunker')
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Determine the language for syntax highlighting
|
| 36 |
def get_language_by_extension(file_extension):
|
|
@@ -45,6 +57,9 @@ def get_language_by_extension(file_extension):
|
|
| 45 |
|
| 46 |
language = get_language_by_extension(file_extension)
|
| 47 |
|
|
|
|
|
|
|
|
|
|
| 48 |
col1, col2 = st.columns(2)
|
| 49 |
|
| 50 |
with col1:
|
|
|
|
| 8 |
with open(file_path, 'r') as file:
|
| 9 |
return json.load(file)
|
| 10 |
|
| 11 |
+
# Function to read code from an uploaded file
|
| 12 |
+
def read_code_from_file(uploaded_file):
|
| 13 |
+
return uploaded_file.getvalue().decode("utf-8")
|
| 14 |
+
|
| 15 |
# Setup Streamlit page
|
| 16 |
st.set_page_config(page_title="Cintra Code Chunker", layout="wide")
|
| 17 |
|
|
|
|
| 25 |
# UI Elements
|
| 26 |
st.title('Cintra Code Chunker')
|
| 27 |
|
| 28 |
+
# Create two columns for file selection and file upload
|
| 29 |
+
col1, col2 = st.columns(2)
|
| 30 |
|
| 31 |
+
with col1:
|
| 32 |
+
# File selection dropdown
|
| 33 |
+
selected_file_name = st.selectbox("Select an example code file", code_files)
|
| 34 |
|
| 35 |
+
with col2:
|
| 36 |
+
# File upload
|
| 37 |
+
uploaded_file = st.file_uploader("Or upload your code file", type=['py', 'js', 'css'])
|
| 38 |
|
| 39 |
+
# Determine the content and file extension based on selection or upload
|
| 40 |
+
if uploaded_file is not None:
|
| 41 |
+
code_content = read_code_from_file(uploaded_file)
|
| 42 |
+
file_extension = uploaded_file.name.split('.')[-1]
|
| 43 |
+
else:
|
| 44 |
+
code_content = code_files_data.get(selected_file_name, "")
|
| 45 |
+
file_extension = selected_file_name.split('.')[-1] if selected_file_name else None
|
| 46 |
|
| 47 |
# Determine the language for syntax highlighting
|
| 48 |
def get_language_by_extension(file_extension):
|
|
|
|
| 57 |
|
| 58 |
language = get_language_by_extension(file_extension)
|
| 59 |
|
| 60 |
+
# User input for Token Chunk Size
|
| 61 |
+
token_chunk_size = st.number_input('Token Chunk Size Target', min_value=5, max_value=1000, value=25)
|
| 62 |
+
|
| 63 |
col1, col2 = st.columns(2)
|
| 64 |
|
| 65 |
with col1:
|