Update chunk.py
Browse files
chunk.py
CHANGED
|
@@ -1,20 +1,24 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
def chunk_text(text, chunk_size=
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
for
|
| 11 |
-
|
| 12 |
-
st.write(chunk)
|
| 13 |
|
| 14 |
# Function to save and download chunked text
|
| 15 |
def save_and_download_chunked_data(chunked_text, file_name="chunked_data.txt"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Combine chunks with delimiters (optional)
|
| 17 |
-
chunked_data = "\n---\n".join(chunked_text)
|
| 18 |
|
| 19 |
# Display download button in Streamlit
|
| 20 |
st.download_button(
|
|
@@ -24,4 +28,13 @@ def save_and_download_chunked_data(chunked_text, file_name="chunked_data.txt"):
|
|
| 24 |
mime="text/plain"
|
| 25 |
)
|
| 26 |
|
| 27 |
-
return chunked_data # Return the combined chunked data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Example function to split text into chunks of a specified size
|
| 4 |
+
def chunk_text(text, chunk_size=2000):
|
| 5 |
+
# Ensure text is non-empty
|
| 6 |
+
if not text:
|
| 7 |
+
return []
|
| 8 |
+
|
| 9 |
+
# Chunk the text into smaller parts
|
| 10 |
+
chunks = [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
|
| 11 |
+
return chunks
|
|
|
|
| 12 |
|
| 13 |
# Function to save and download chunked text
|
| 14 |
def save_and_download_chunked_data(chunked_text, file_name="chunked_data.txt"):
|
| 15 |
+
# Ensure chunked_text is non-empty
|
| 16 |
+
if not chunked_text:
|
| 17 |
+
st.warning("No chunked data to download.")
|
| 18 |
+
return
|
| 19 |
+
|
| 20 |
# Combine chunks with delimiters (optional)
|
| 21 |
+
chunked_data = "\n---\n".join(chunked_text) # Add a separator between chunks
|
| 22 |
|
| 23 |
# Display download button in Streamlit
|
| 24 |
st.download_button(
|
|
|
|
| 28 |
mime="text/plain"
|
| 29 |
)
|
| 30 |
|
| 31 |
+
return chunked_data # Return the combined chunked data if needed
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# Function to display chunks in Streamlit
|
| 35 |
+
def display_chunks(text, chunk_size=1000):
|
| 36 |
+
for j, chunk in enumerate(chunk_text(text, chunk_size)):
|
| 37 |
+
st.write(f"**Chunk {j+1}:**")
|
| 38 |
+
st.write(chunk)
|
| 39 |
+
|
| 40 |
+
|