|
import streamlit as st |
|
|
|
|
|
def chunk_text(text, chunk_size=2000): |
|
|
|
if not text: |
|
return [] |
|
|
|
|
|
chunks = [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)] |
|
return chunks |
|
|
|
|
|
def save_and_download_chunked_data(chunked_text, file_name="chunked_data.txt"): |
|
|
|
if not chunked_text: |
|
st.warning("No chunked data to download.") |
|
return |
|
|
|
|
|
chunked_data = "\n---\n".join(chunked_text) |
|
|
|
|
|
st.download_button( |
|
label="Download Chunked Data", |
|
data=chunked_data, |
|
file_name=file_name, |
|
mime="text/plain" |
|
) |
|
|
|
return chunked_data |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|