Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,23 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
-
|
4 |
|
5 |
-
|
|
|
|
|
|
|
6 |
|
7 |
-
st.title("
|
8 |
|
9 |
-
|
10 |
|
11 |
-
if
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
|
5 |
+
# Load pre-trained model and tokenizer
|
6 |
+
model_name = "username/my_spam_detector" # replace 'username' with your Hugging Face account name
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
|
10 |
+
st.title("Spam Detector")
|
11 |
|
12 |
+
text = st.text_input("Enter a text")
|
13 |
|
14 |
+
if st.button('Predict'):
|
15 |
+
# Tokenize the input text
|
16 |
+
inputs = tokenizer(text, return_tensors='pt')
|
17 |
|
18 |
+
# Get model's prediction
|
19 |
+
outputs = model(**inputs)
|
20 |
+
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
21 |
|
22 |
+
# Show prediction
|
23 |
+
st.write(f"The probability of the text being spam is {probs[0][1].item() * 100:.2f}%.")
|
|