Upload 3 files
Browse filesRAG Splitter System
![Rag System Profile.png](https://cdn-uploads.huggingface.co/production/uploads/652cfcbcff2202020ed520c2/sAAFZWoCqVRRd0GDmBWYm.png)
What does it do?
The RAG Splitter System allows you to:
• Select from various text splitters: Recursive Splitter, HTML Splitter, Markdown Splitter, Code Splitter, Token Splitter, Character Splitter, and Semantic Chunker.
• Process your data: Easily split and analyze text data based on your chosen method.
• View outputs clearly: Each splitter’s result is displayed in an organized manner, providing clarity and insight.
Key Features:
• User-friendly interface: Choose your splitter type and see the results instantly.
• Informative: Each splitter comes with a brief description to help you understand its purpose and functionality.
• Aesthetic design: With a streamlined layout and customizable styling, the app is both functional and visually appealing.
<h2 style="font-family: 'poppins'; font-weight: bold; color: Green;">👨💻 Author: Irfan Ullah Khan</h2>
My Portfolio :https://flowcv.me/ikm
- .gitattributes +1 -0
- Rag System Profile.png +3 -0
- app.py +101 -0
- requirements.txt +0 -0
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
Rag[[:space:]]System[[:space:]]Profile.png filter=lfs diff=lfs merge=lfs -text
|
Git LFS Details
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import re
|
3 |
+
|
4 |
+
# Define the split functions
|
5 |
+
def recursive_splitter(data):
|
6 |
+
paragraphs = data.split('\n\n')
|
7 |
+
sentences = [sentence for para in paragraphs for sentence in para.split('.')]
|
8 |
+
return [sentence.strip() + '.' for sentence in sentences if sentence.strip()]
|
9 |
+
|
10 |
+
def html_splitter(data):
|
11 |
+
parts = re.split(r'(<[^>]+>)', data)
|
12 |
+
return [part for part in parts if part.strip()]
|
13 |
+
|
14 |
+
def markdown_splitter(data):
|
15 |
+
parts = re.split(r'(^#{1,6} .*$)', data, flags=re.MULTILINE)
|
16 |
+
return [part.strip() for part in parts if part.strip()]
|
17 |
+
|
18 |
+
def code_splitter(data):
|
19 |
+
parts = re.split(r'(?m)^def ', data)
|
20 |
+
return [f'def {part.strip()}' if idx > 0 else part.strip() for idx, part in enumerate(parts) if part.strip()]
|
21 |
+
|
22 |
+
def token_splitter(data):
|
23 |
+
tokens = re.findall(r'\b\w+\b', data)
|
24 |
+
return tokens
|
25 |
+
|
26 |
+
def character_splitter(data):
|
27 |
+
return list(data)
|
28 |
+
|
29 |
+
def semantic_chunker(data):
|
30 |
+
sentences = re.split(r'(?<=\.)\s+', data)
|
31 |
+
return [sentence.strip() for sentence in sentences if sentence.strip()]
|
32 |
+
|
33 |
+
# Mapping splitter names to functions and descriptions
|
34 |
+
splitter_details = {
|
35 |
+
"Recursive Splitter": {
|
36 |
+
"function": recursive_splitter,
|
37 |
+
"description": "Recursively splits the data into smaller chunks, like paragraphs into sentences. Useful for processing text at different levels of granularity."
|
38 |
+
},
|
39 |
+
"HTML Splitter": {
|
40 |
+
"function": html_splitter,
|
41 |
+
"description": "Splits data based on HTML tags, making it easier to work with structured web content, such as isolating specific sections of HTML code."
|
42 |
+
},
|
43 |
+
"Markdown Splitter": {
|
44 |
+
"function": markdown_splitter,
|
45 |
+
"description": "Splits markdown content based on headings (e.g., '# ', '## '). Useful for processing documents written in Markdown format."
|
46 |
+
},
|
47 |
+
"Code Splitter": {
|
48 |
+
"function": code_splitter,
|
49 |
+
"description": "Splits programming code into logical blocks like functions or classes. Useful for code analysis and documentation."
|
50 |
+
},
|
51 |
+
"Token Splitter": {
|
52 |
+
"function": token_splitter,
|
53 |
+
"description": "Splits data into individual tokens/words, which is often the first step in natural language processing (NLP) tasks."
|
54 |
+
},
|
55 |
+
"Character Splitter": {
|
56 |
+
"function": character_splitter,
|
57 |
+
"description": "Splits text into individual characters. Useful for character-level analysis or encoding tasks."
|
58 |
+
},
|
59 |
+
"Semantic Chunker": {
|
60 |
+
"function": semantic_chunker,
|
61 |
+
"description": "Splits data based on semantic meaning, typically by sentences. Ensures that related information stays together."
|
62 |
+
},
|
63 |
+
}
|
64 |
+
|
65 |
+
# Streamlit app
|
66 |
+
st.sidebar.title("Splitter Settings")
|
67 |
+
st.sidebar.subheader("Data Input")
|
68 |
+
user_data = st.sidebar.text_area("Enter the data you want to split:", "This is a sample text. Enter your data here...")
|
69 |
+
|
70 |
+
st.sidebar.subheader("Splitter Type")
|
71 |
+
splitter_type = st.sidebar.selectbox(
|
72 |
+
"Choose a splitter type:",
|
73 |
+
list(splitter_details.keys())
|
74 |
+
)
|
75 |
+
|
76 |
+
st.sidebar.subheader("Options")
|
77 |
+
show_info = st.sidebar.checkbox("Show information about all splitter types")
|
78 |
+
|
79 |
+
st.title("RAG Splitter System")
|
80 |
+
st.markdown('<p class="title">Developed By: Irfan Ullah Khan</p>', unsafe_allow_html=True)
|
81 |
+
|
82 |
+
# Display selected splitter description
|
83 |
+
st.subheader(f"Selected Splitter: {splitter_type}")
|
84 |
+
st.write(splitter_details[splitter_type]["description"])
|
85 |
+
|
86 |
+
# Processing
|
87 |
+
if st.button("Split Data"):
|
88 |
+
with st.spinner('Processing data...'):
|
89 |
+
splitter_function = splitter_details[splitter_type]["function"]
|
90 |
+
split_output = splitter_function(user_data)
|
91 |
+
|
92 |
+
if split_output:
|
93 |
+
st.subheader(f"Output using {splitter_type}")
|
94 |
+
for idx, part in enumerate(split_output):
|
95 |
+
st.write(f"**Part {idx + 1}:**")
|
96 |
+
st.write(part)
|
97 |
+
|
98 |
+
if show_info:
|
99 |
+
for name, details in splitter_details.items():
|
100 |
+
st.subheader(name)
|
101 |
+
st.write(details["description"])
|
Binary file (72 Bytes). View file
|
|