File size: 1,926 Bytes
1341b77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0744724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1341b77
 
 
 
0744724
1341b77
 
 
0744724
 
 
1341b77
 
 
f8d166f
1341b77
e00628f
 
1341b77
 
 
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
import gradio as gr
import torch
from torch import tensor
from torch.nn import functional as F
from sklearn.preprocessing import LabelEncoder
import pandas as pd

label_encoder = LabelEncoder()

coeffs = torch.load('fakejobposts.pth')

indep_cols = ['job_title', 'company_name', 'company_desc', 'job_desc',
              'job_requirement', 'salary', 'location', 'employment_type',
              'department']

def calc_preds(coeffs, indeps):
    layers, consts = coeffs
    n = len(layers)
    res = indeps
    for i, l in enumerate(layers):
        res = res @ l + consts[i]
        if i != n-1:
            res = F.relu(res)
    if torch.sigmoid(res) > 0.5:
        return 'Real Job Post'
    else:
        return 'Fake Job Post'
    # return torch.sigmoid(res)


def preprocess_input(input_data):
    df = pd.DataFrame([input_data], columns=indep_cols)

    for column in df.columns:
        if df[column].dtype == 'O':  # 'O' stands for object type (string)
            df[column] = label_encoder.fit_transform(df[column])
        else:
            df[column] = df[column].astype(float)

    t_indep = tensor(df[indep_cols].values, dtype=torch.float)
    vals, indices = t_indep.max(dim=0)
    t_indep = t_indep / vals

    return t_indep

def main(inputs):
    t_indep = preprocess_input(inputs)
    return calc_preds(coeffs, t_indep)

def main(job_title, company_name, company_desc, job_desc,
              job_requirement, salary, location, employment_type,
              department):
    inputs = [job_title, company_name, company_desc, job_desc,
              job_requirement, salary, location, employment_type,
              department]

    t_indep = preprocess_input(inputs)
    
    return calc_preds(coeffs, t_indep)

iface = gr.Interface(
    fn=main,
    inputs="text",
    outputs="text",
    title="Real/Fake Job Posting Identifier",
    description="Identifies job posts as real or fake."
)

iface.launch()