Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the pre-trained model and tokenizer from Hugging Face
|
| 6 |
+
model_name = "tajuarAkash/test2" # Replace with your Hugging Face model path
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 10 |
+
|
| 11 |
+
# Title of the web app
|
| 12 |
+
st.title("Fraud Detection in Health Insurance Claims")
|
| 13 |
+
|
| 14 |
+
# Description of the app
|
| 15 |
+
st.write("This app predicts whether a health insurance claim is fraudulent based on the input data.")
|
| 16 |
+
|
| 17 |
+
# Create a text box for the user to input the generated sentence (feature for prediction)
|
| 18 |
+
input_text = st.text_area("Enter the claim description")
|
| 19 |
+
|
| 20 |
+
# Create a button to make predictions
|
| 21 |
+
if st.button('Predict Fraud'):
|
| 22 |
+
if input_text:
|
| 23 |
+
# Tokenize the input text
|
| 24 |
+
inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 25 |
+
|
| 26 |
+
# Get model predictions
|
| 27 |
+
with torch.no_grad():
|
| 28 |
+
logits = model(**inputs).logits
|
| 29 |
+
predicted_class = torch.argmax(logits, dim=-1).item()
|
| 30 |
+
|
| 31 |
+
# Display the result
|
| 32 |
+
if predicted_class == 1:
|
| 33 |
+
st.write("This claim is predicted to be fraudulent.")
|
| 34 |
+
else:
|
| 35 |
+
st.write("This claim is predicted to be legitimate.")
|
| 36 |
+
else:
|
| 37 |
+
st.write("Please enter a claim description.")
|