PEF / app.py
allenchienxxx's picture
Update app.py
4a604a4
raw
history blame
1.6 kB
from analze import *
import streamlit as st
def is_valid_filetype(file):
valid_extensions = ['.eml', '.txt']
return any(file.name.endswith(ext) for ext in valid_extensions)
def main():
st.title("Phishing Email Filtering Service")
uploaded_file = st.file_uploader("Upload a file", type=['eml', 'txt'])
if uploaded_file is not None:
if is_valid_filetype(uploaded_file):
st.success("File uploaded successfully!")
# Process the file here
else:
st.error("Invalid file type. Please upload an EML or TXT file.")
def upload_file():
if request.method == 'POST':
# Check if a file was uploaded
if 'file' not in request.files:
return render_template('home.html', content='No file uploaded.')
file = request.files['file']
# Check if the file has a filename
if file.filename == '':
return render_template('home.html', content='No file selected.')
filepath = 'email files/' + file.filename
return render_template('home.html',
content=check_file_type(file),
features = get_features(filepath),
pre_content=predict_content(text_feature(filepath)),
pre_tag=predict_html(html_tags_feature(filepath)),
pre_num=predict_num(num_feature(filepath)),
pre_extra=predict_extra(extra_feature(filepath)))
return render_template('home.html')
if __name__ == '__main__':
main()