Spaces:
Build error
Build error
Upload 2 files
Browse files- app.py +35 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Load tokenizer and model from Hugging Face Hub
|
| 7 |
+
MODEL_NAME = "briangilbert/working"
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
|
| 10 |
+
|
| 11 |
+
# Define labels
|
| 12 |
+
id2label = {0: "NOT SCAM", 1: "SCAM"}
|
| 13 |
+
|
| 14 |
+
# Streamlit UI
|
| 15 |
+
st.title("💬 Fraud Detection in Text")
|
| 16 |
+
st.write("Enter a dialogue and check if it's a **SCAM** or **NOT SCAM**.")
|
| 17 |
+
|
| 18 |
+
# Text input
|
| 19 |
+
user_input = st.text_area("Enter a message:")
|
| 20 |
+
|
| 21 |
+
if st.button("Detect Fraud"):
|
| 22 |
+
if user_input:
|
| 23 |
+
# Tokenize input
|
| 24 |
+
inputs = tokenizer(user_input, return_tensors="pt", truncation=True)
|
| 25 |
+
|
| 26 |
+
# Get model prediction
|
| 27 |
+
model.eval()
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
outputs = model(**inputs)
|
| 30 |
+
predicted_class = torch.argmax(outputs.logits).item()
|
| 31 |
+
|
| 32 |
+
# Display result
|
| 33 |
+
st.success(f"🚨 Prediction: **{id2label[predicted_class]}**")
|
| 34 |
+
else:
|
| 35 |
+
st.warning("Please enter a dialogue.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
torch
|
| 3 |
+
transformers
|