Vinay-M commited on
Commit
950d2fc
·
1 Parent(s): ef1c326

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,20 +1,23 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
- from PIL import Image
4
 
5
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
 
 
6
 
7
- st.title("Hot Dog? Or Not?")
8
 
9
- file_name = st.file_uploader("Upload a hot dog candidate image")
10
 
11
- if file_name is not None:
12
- col1, col2 = st.columns(2)
 
13
 
14
- image = Image.open(file_name)
15
- col1.image(image, use_column_width=True)
16
- predictions = pipeline(image)
17
 
18
- col2.header("Probabilities")
19
- for p in predictions:
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}%.")