-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (51 loc) · 2.33 KB
/
app.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
from preprocessing import cleaners, tokenization, lemmatization
from utils import download_utils
import pandas as pd
import nltk
# Download NLTK data
nltk.download('punkt')
nltk.download('stopwords')
nltk.download('wordnet')
def preprocess_options(data):
st.sidebar.header("Preprocessing Options")
text_column = st.sidebar.selectbox("Select text column", data.columns)
# Text cleaning options
st.sidebar.subheader("Text Cleaning")
lowercase = st.sidebar.checkbox("Convert to lowercase")
remove_urls = st.sidebar.checkbox("Remove URLs")
remove_non_word = st.sidebar.checkbox("Remove non-word characters")
remove_digits = st.sidebar.checkbox("Remove numerical digits")
# Tokenization and stopwords options
st.sidebar.subheader("Tokenization")
tokenize_text = st.sidebar.checkbox("Tokenize text")
remove_stopwords = st.sidebar.checkbox("Remove stopwords")
# Stemming and lemmatization options
st.sidebar.subheader("Stemming and Lemmatization")
apply_stemming = st.sidebar.checkbox("Apply stemming")
apply_lemmatization = st.sidebar.checkbox("Apply lemmatization")
if st.sidebar.button("Apply Preprocessing"):
if lowercase or remove_urls or remove_non_word or remove_digits:
data = cleaners.text_cleaning(data, text_column, lowercase, remove_urls, remove_non_word, remove_digits)
if tokenize_text:
data = tokenization.tokenize(data, text_column)
if remove_stopwords:
data = tokenization.remove_stopwords(data, text_column)
if apply_stemming:
data = lemmatization.stemming(data, text_column)
if apply_lemmatization:
data = lemmatization.lemmatization(data, text_column)
st.write("Preprocessed Data")
st.dataframe(data)
tmp_download_link = download_utils.download_link(data, 'preprocessed_text_data.csv', 'Download preprocessed text data')
st.markdown(tmp_download_link, unsafe_allow_html=True)
def main():
st.title("CSV Text Preprocessing App")
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
if uploaded_file is not None:
data = pd.read_csv(uploaded_file)
st.write("Original Data")
st.dataframe(data)
preprocess_options(data)
if __name__ == "__main__":
main()