Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Load Enron Dataset
|
| 7 |
+
@st.cache
|
| 8 |
+
def load_data():
|
| 9 |
+
dataset = load_dataset('enron_email')
|
| 10 |
+
return dataset['train']
|
| 11 |
+
|
| 12 |
+
data = load_data()
|
| 13 |
+
|
| 14 |
+
# Load models
|
| 15 |
+
sentiment_model = pipeline('sentiment-analysis')
|
| 16 |
+
ner_model = pipeline('ner', aggregation_strategy="simple")
|
| 17 |
+
topic_model = pipeline('zero-shot-classification', model='facebook/bart-large-mnli')
|
| 18 |
+
|
| 19 |
+
# Streamlit UI
|
| 20 |
+
st.title('Enron Email Analysis')
|
| 21 |
+
|
| 22 |
+
st.sidebar.title('Options')
|
| 23 |
+
email_id = st.sidebar.selectbox('Select Email ID', range(len(data)))
|
| 24 |
+
|
| 25 |
+
email_text = data[email_id]['text']
|
| 26 |
+
st.write(f"## Email Content\n{email_text}")
|
| 27 |
+
|
| 28 |
+
# Sentiment Analysis
|
| 29 |
+
st.write("## Sentiment Analysis")
|
| 30 |
+
sentiment = sentiment_model(email_text)
|
| 31 |
+
st.write(sentiment)
|
| 32 |
+
|
| 33 |
+
# Named Entity Recognition
|
| 34 |
+
st.write("## Named Entity Recognition (NER)")
|
| 35 |
+
entities = ner_model(email_text)
|
| 36 |
+
st.write(entities)
|
| 37 |
+
|
| 38 |
+
# Topic Modeling (Zero-Shot Classification)
|
| 39 |
+
st.write("## Topic Modeling")
|
| 40 |
+
labels = ['business', 'personal', 'financial', 'legal', 'politics']
|
| 41 |
+
topics = topic_model(email_text, candidate_labels=labels)
|
| 42 |
+
st.write(topics)
|