Makima57 commited on
Commit
a08cb71
1 Parent(s): 05f7c2a

Update chunk.py

Browse files
Files changed (1) hide show
  1. chunk.py +25 -12
chunk.py CHANGED
@@ -1,20 +1,24 @@
1
  import streamlit as st
2
 
3
- # Function to chunk text into smaller parts
4
- def chunk_text(text, chunk_size=1000):
5
- for i in range(0, len(text), chunk_size):
6
- yield text[i:i + chunk_size]
7
-
8
- # Function to display chunks in Streamlit
9
- def display_chunks(text, chunk_size=1000):
10
- for j, chunk in enumerate(chunk_text(text, chunk_size)):
11
- st.write(f"**Chunk {j+1}:**")
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 for further use if needed
 
 
 
 
 
 
 
 
 
 
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
+