File size: 2,291 Bytes
dd204e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from model_functions import *
from preprocessor import *
import streamlit as st
import pandas as pd



def main():
    st.title("WhatsApp Analysis Tool")

    # File uploader
    uploaded_file = st.file_uploader("Choose a file (.txt or .zip)", type=['txt', 'zip'])
    if uploaded_file is not None:
        file_type = detect_file_type(uploaded_file.name)
        if file_type in ["txt", "zip"]:
            # Process the file
            data = preprocess_whatsapp_messages(uploaded_file, file_type)
            if data.empty:
                st.write("No messages found or the file could not be processed.")
            else:
                # Date selector
                date_options = data['date'].dt.strftime('%Y-%m-%d').unique()
                selected_date = st.selectbox("Select a date for analysis:", date_options)

                if selected_date:
                    text_for_analysis = get_dated_input(data, selected_date)
                    with st.expander("Show/Hide Original Conversation"):
                        st.markdown(f"```\n{text_for_analysis}\n```", unsafe_allow_html=True)

                    # Load models
                    tokenizer_sentiment, model_sentiment = load_sentiment_analyzer()
                    tokenizer_summary, model_summary = load_summarizer()
                    pipe_ner = load_NER()

                    # Perform analysis
                    sentiment = get_sentiment_analysis(text_for_analysis, tokenizer_sentiment, model_sentiment)
                    summary = generate_summary(text_for_analysis, tokenizer_summary, model_summary)
                    ner_results = get_NER(text_for_analysis, pipe_ner)

                    # Display results
                    st.subheader("Sentiment Analysis")
                    st.write("Sentiment:", sentiment)

                    st.subheader("Summary")
                    st.write("Summary:", summary)

                    st.subheader("Named Entity Recognition")
                    ner_df = pd.DataFrame(ner_results, columns=["Word", "Entity Group"])
                    st.write(ner_df)
        else:
            st.error("Unsupported file type. Please upload a .txt or .zip file.")
    else:
        st.info("Please upload a file to proceed.")

if __name__ == "__main__":
    main()