File size: 2,757 Bytes
4736ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e8b885
4736ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import streamlit as st
from huggingface_hub import hf_hub_download
from model import JobFakeModel
import torch
import torch.nn.functional as F
from data_processing import get_tokens
import numpy as np
import time

def get_model_list():
    model_name = "sebastiansarasti/fakeJobs"  
    filename = "best_model.pth"  
    file_path = hf_hub_download(repo_id=model_name, filename=filename)
    return file_path

def load_model(path):
    model = JobFakeModel(base_model="distilbert", freeze_base=True)
    model.load_state_dict(torch.load(path, device="cpu"))
    return model

st.title('Fake Jobs Streamlit App')
st.write('This is a fake jobs streamlit app')

# download the model
path = get_model_list()
model = load_model(path)

with st.sidebar:
    st.subheader('About the App')
    st.markdown('Data used for the training come from the following source: https://www.kaggle.com/datasets/shivamb/real-or-fake-fake-jobposting-prediction')
    st.empty()
    st.subheader('Author')
    st.markdown('Sebastián Sarasti Zambonino')
    st.markdown('Data Scientist - Machine Learning Engineer')
    st.markdown('https://www.linkedin.com/in/sebastiansarasti/')
    st.markdown('https://github.com/sebassaras02')

# Create columns for the inputs
col1, col2, col3 = st.columns(3)

with col1:
    # Create an input text box for the description
    description = st.text_area('Description', 'Enter the job description here')

with col2:
    # Create an input text box for the requirements
    requirements = st.text_area('Requirements', 'Enter the job requirements here')

with col3:
    # Create an input text box for the benefits
    benefits = st.text_area('Benefits', 'Enter the job benefits here')

# if benefits is none, set it to an empty nothing
if benefits is None:
    benefits = 'Nothing'
elif requirements is None:
    requirements = 'Nothing'
elif description is None:
    raise ValueError('Description cannot be empty')

# Create a button to submit the job
with st.spinner('Wait for it...'):
    time.sleep(2)
    if st.button('Submit Job'):
        tokens_des = get_tokens(description)
        tokens_req = get_tokens(requirements)
        tokens_ben = get_tokens(benefits)
        model.eval()
        with torch.no_grad():
            output = model(tokens_des, tokens_req, tokens_ben)
        # calculate the probability
        output = F.sigmoid(output).item()*100
        # Create a box to show the result
        st.metric('Fake Job Probability', f"{np.round(output, 5)}%")
        if output > 75:
            st.error('⚠️ High probability of being a fake job!')
        elif output > 50:
            st.warning('⚠️ Medium probability of being a fake job')
        else:
            st.success('✅ Low probability of being a fake job')