File size: 1,638 Bytes
01cbf36
4a604a4
 
 
 
 
 
 
 
 
 
 
 
 
0a2c406
4a604a4
 
01cbf36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a604a4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
            save_file(upload_file)
        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()