Spaces:
Runtime error
Runtime error
marcelomoreno26
commited on
Commit
•
dd204e1
1
Parent(s):
37bb3c2
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from model_functions import *
|
2 |
+
from preprocessor import *
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
def main():
|
9 |
+
st.title("WhatsApp Analysis Tool")
|
10 |
+
|
11 |
+
# File uploader
|
12 |
+
uploaded_file = st.file_uploader("Choose a file (.txt or .zip)", type=['txt', 'zip'])
|
13 |
+
if uploaded_file is not None:
|
14 |
+
file_type = detect_file_type(uploaded_file.name)
|
15 |
+
if file_type in ["txt", "zip"]:
|
16 |
+
# Process the file
|
17 |
+
data = preprocess_whatsapp_messages(uploaded_file, file_type)
|
18 |
+
if data.empty:
|
19 |
+
st.write("No messages found or the file could not be processed.")
|
20 |
+
else:
|
21 |
+
# Date selector
|
22 |
+
date_options = data['date'].dt.strftime('%Y-%m-%d').unique()
|
23 |
+
selected_date = st.selectbox("Select a date for analysis:", date_options)
|
24 |
+
|
25 |
+
if selected_date:
|
26 |
+
text_for_analysis = get_dated_input(data, selected_date)
|
27 |
+
with st.expander("Show/Hide Original Conversation"):
|
28 |
+
st.markdown(f"```\n{text_for_analysis}\n```", unsafe_allow_html=True)
|
29 |
+
|
30 |
+
# Load models
|
31 |
+
tokenizer_sentiment, model_sentiment = load_sentiment_analyzer()
|
32 |
+
tokenizer_summary, model_summary = load_summarizer()
|
33 |
+
pipe_ner = load_NER()
|
34 |
+
|
35 |
+
# Perform analysis
|
36 |
+
sentiment = get_sentiment_analysis(text_for_analysis, tokenizer_sentiment, model_sentiment)
|
37 |
+
summary = generate_summary(text_for_analysis, tokenizer_summary, model_summary)
|
38 |
+
ner_results = get_NER(text_for_analysis, pipe_ner)
|
39 |
+
|
40 |
+
# Display results
|
41 |
+
st.subheader("Sentiment Analysis")
|
42 |
+
st.write("Sentiment:", sentiment)
|
43 |
+
|
44 |
+
st.subheader("Summary")
|
45 |
+
st.write("Summary:", summary)
|
46 |
+
|
47 |
+
st.subheader("Named Entity Recognition")
|
48 |
+
ner_df = pd.DataFrame(ner_results, columns=["Word", "Entity Group"])
|
49 |
+
st.write(ner_df)
|
50 |
+
else:
|
51 |
+
st.error("Unsupported file type. Please upload a .txt or .zip file.")
|
52 |
+
else:
|
53 |
+
st.info("Please upload a file to proceed.")
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
main()
|