JustinSpace / app.py
JustHuggingFaces's picture
Update app.py
34dda3a verified
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)