File size: 1,446 Bytes
44ee5e5
 
570a6f9
 
 
 
2c7a90e
570a6f9
3663d08
5833955
3663d08
 
44ee5e5
570a6f9
d64d5d5
44ee5e5
ed8d79b
44ee5e5
 
570a6f9
0500fd7
570a6f9
 
 
0500fd7
 
 
2c7a90e
c00d4c0
0500fd7
34dda3a
2c7a90e
0500fd7
d64d5d5
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
import streamlit as st
from transformers import pipeline
import soundfile as sf
from txtai.pipeline import TextToSpeech

# Load the text classification model pipeline, filter out the spam and leave the ham
classifier = pipeline("text-classification", model='JustHuggingFaces/OptimalSpamDetect')
to_speech = TextToSpeech("NeuML/ljspeech-jets-onnx")
# Set the images for better user experience
ham_pic = ""
spam_pic = "https://inst.eecs.berkeley.edu/~cs10/labs/cur/programming/data/spam-ham/1-introduction.html?topic=berkeley_bjc%2Fareas%2Fdata.topic"

# Streamlit application title
st.title("Reading Ham")
st.write("Classification for Spam Email: Spam or  Ham?")
# Text input for user to enter the text to classify
text = st.text_area("Paste the email text to classify, if it's a ham, read out", "")
# Perform text classification when the user clicks the "Classify" button
if st.button("Classify"):
    # Perform text classification on the input text
    result = classifier(text)[0]
    # Display the classification result
    spam = "LABEL_1"
    ham = "LABEL_0"
    if result['label'] == spam:
        #st.write("Text:", text)
        st.write("Spam!")
        #st.write("Label: ", result['label'])
        #st.image(spam_pic, caption="It's a spam!")
    else:
        st.write("Ham! Generating speech...")
        #st.write("Label: ", result['label'])
        speech = to_speech(text)
        st.audio(speech, sample_rate=16000, autoplay=True)