Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
-
import torch
|
3 |
from PIL import Image
|
4 |
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
5 |
|
6 |
# Initialize the image-to-text pipeline and models
|
7 |
@st.cache(allow_output_mutation=True)
|
8 |
def load_models():
|
|
|
9 |
image_pipeline = pipeline("image-to-text", model="microsoft/trocr-large-printed")
|
10 |
phishing_model = AutoModelForSequenceClassification.from_pretrained("kithangw/phishing_link_detection", num_labels=2)
|
11 |
phishing_tokenizer = AutoTokenizer.from_pretrained("google/bert_uncased_L-2_H-128_A-2")
|
@@ -31,21 +31,32 @@ def check_phishing(url_for_recognize):
|
|
31 |
|
32 |
# Streamlit interface
|
33 |
st.title("Phishing URL Detection from Image")
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
if uploaded_image is not None:
|
37 |
image = Image.open(uploaded_image)
|
38 |
st.image(image, caption='Uploaded URL Image', use_column_width=True)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from PIL import Image
|
3 |
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
4 |
|
5 |
# Initialize the image-to-text pipeline and models
|
6 |
@st.cache(allow_output_mutation=True)
|
7 |
def load_models():
|
8 |
+
# Make sure to use the correct model names and tokenizer
|
9 |
image_pipeline = pipeline("image-to-text", model="microsoft/trocr-large-printed")
|
10 |
phishing_model = AutoModelForSequenceClassification.from_pretrained("kithangw/phishing_link_detection", num_labels=2)
|
11 |
phishing_tokenizer = AutoTokenizer.from_pretrained("google/bert_uncased_L-2_H-128_A-2")
|
|
|
31 |
|
32 |
# Streamlit interface
|
33 |
st.title("Phishing URL Detection from Image")
|
34 |
+
|
35 |
+
# Text box for URL input
|
36 |
+
verified_url = st.text_input("Enter or paste a URL to check for phishing:")
|
37 |
+
|
38 |
+
# File uploader to scan the image
|
39 |
+
uploaded_image = st.file_uploader("Alternatively, upload an image of the URL", type=["png", "jpg", "jpeg"])
|
40 |
|
41 |
if uploaded_image is not None:
|
42 |
image = Image.open(uploaded_image)
|
43 |
st.image(image, caption='Uploaded URL Image', use_column_width=True)
|
44 |
|
45 |
+
try:
|
46 |
+
# Process the image with the OCR pipeline
|
47 |
+
ocr_result = image_pipeline(image)[0]['generated_text'].replace(" ", "").lower()
|
48 |
+
# Update the text input with the OCR result
|
49 |
+
st.session_state['verified_url'] = ocr_result
|
50 |
+
except Exception as e:
|
51 |
+
st.error(f"An error occurred during image processing: {e}")
|
52 |
+
|
53 |
+
if st.button('Detect Phishing'):
|
54 |
+
if verified_url:
|
55 |
+
result = check_phishing(verified_url)
|
56 |
+
st.write(result)
|
57 |
+
else:
|
58 |
+
st.write("Please enter or upload a URL to check for phishing.")
|
59 |
+
|
60 |
+
# Ensure the text box is updated with the OCR result (if any)
|
61 |
+
if 'verified_url' in st.session_state and uploaded_image:
|
62 |
+
verified_url = st.session_state['verified_url']
|