|
import streamlit as st
|
|
|
|
st.set_page_config(page_title="Turkish Text Classification - via AG", page_icon='📖')
|
|
st.header("📖Spam Mail Classification - TR")
|
|
|
|
with st.sidebar:
|
|
hf_key = st.text_input("HuggingFace Access Key", key="hf_key", type="password")
|
|
|
|
MODEL_SPAM = {
|
|
"albert": "anilguven/albert_tr_turkish_spam_email",
|
|
"distilbert": "anilguven/distilbert_tr_turkish_spam_email",
|
|
"bert": "anilguven/bert_tr_turkish_spam_email",
|
|
"electra": "anilguven/electra_tr_turkish_spam_email",
|
|
}
|
|
|
|
MODEL_SPAMS = ["albert","distilbert","bert","electra"]
|
|
|
|
|
|
from transformers import pipeline
|
|
|
|
def format_model_name(model_key):
|
|
name_parts = model_key
|
|
formatted_name = ''.join(name_parts)
|
|
return formatted_name
|
|
|
|
formatted_names_to_identifiers = {
|
|
format_model_name(key): key for key in MODEL_SPAM.keys()
|
|
}
|
|
|
|
|
|
|
|
|
|
with st.expander("About this app"):
|
|
st.write(f"""
|
|
1-Choose your model for spam mail classification (ham or spam mail).\n
|
|
2-Enter your sample mail.\n
|
|
3-And model predict your mail's result.
|
|
""")
|
|
|
|
model_name: str = st.selectbox("Model", options=MODEL_SPAMS)
|
|
selected_model = MODEL_SPAM[model_name]
|
|
|
|
if not hf_key:
|
|
st.info("Please add your HuggingFace Access Key to continue.")
|
|
st.stop()
|
|
|
|
access_token = hf_key
|
|
pipe = pipeline("text-classification", model=selected_model, token=access_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model_display_name = selected_model
|
|
st.write(f"Model being used: `{model_display_name}`")
|
|
|
|
|
|
comment = st.text_input("Enter your mail text for analysis")
|
|
|
|
st.text('')
|
|
if st.button("Submit for Analysis"):
|
|
if not hf_key:
|
|
st.info("Please add your HuggingFace Access Key to continue.")
|
|
st.stop()
|
|
else:
|
|
result = pipe(comment)[0]
|
|
label=''
|
|
if result["label"] == "LABEL_0": label = "Ham mail"
|
|
else: label = "Spam mail"
|
|
st.text(label + " with " + str(result["score"]) + " accuracy")
|
|
|
|
|
|
|