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