Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,25 @@
|
|
1 |
-
import
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
-
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
|
4 |
-
model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=2)
|
5 |
|
6 |
-
|
|
|
|
|
7 |
encoded_text = tokenizer(text, truncation=True, padding='max_length', max_length=512, return_tensors='pt')
|
8 |
predictions = model(**encoded_text)
|
9 |
-
|
10 |
-
predicted_class =
|
11 |
-
|
12 |
return predicted_class
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
|
|
3 |
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("mrm8488/bert-tiny-finetuned-sms-spam-detection")
|
5 |
+
model = AutoModelForSequenceClassification.from_pretrained("mrm8488/bert-tiny-finetuned-sms-spam-detection")
|
6 |
+
def classify_spam(text):
|
7 |
encoded_text = tokenizer(text, truncation=True, padding='max_length', max_length=512, return_tensors='pt')
|
8 |
predictions = model(**encoded_text)
|
9 |
+
predicted_probabilities = predictions.logits.softmax(dim=1)
|
10 |
+
predicted_class = "Spam" if predicted_probabilities[0, 1] > 0.5 else "Not Spam"
|
|
|
11 |
return predicted_class
|
12 |
+
def main():
|
13 |
+
st.title("SMS Spam Classification App")
|
14 |
+
st.text("Made by Moneeb Ahmad with Lil Love ❤️ ")
|
15 |
+
text_input = st.text_area("Enter SMS text for classification:", "")
|
16 |
+
if st.button("Classify"):
|
17 |
+
if text_input:
|
18 |
+
result = classify_spam(text_input)
|
19 |
+
st.subheader("Predicted Class:")
|
20 |
+
st.write(result)
|
21 |
+
else:
|
22 |
+
st.warning("Please enter some text for classification.")
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
main()
|