Spaces:
Runtime error
Runtime error
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() |