query-app / chunk.py
Makima57's picture
Update chunk.py
e3ff8ef verified
raw
history blame
911 Bytes
import streamlit as st
# Function to chunk text into smaller parts
def chunk_text(text, chunk_size=1000):
for i in range(0, len(text), chunk_size):
yield text[i:i + chunk_size]
# 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)
# Function to save and download chunked text
def save_and_download_chunked_data(chunked_text, file_name="chunked_data.txt"):
# Combine chunks with delimiters (optional)
chunked_data = "\n---\n".join(chunked_text)
# 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 for further use if needed