FakeJobPost / app.py
Gabriel
debug
7dedc87
raw
history blame
1.53 kB
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 torch.sigmoid(res)
def main(job_title, company_name, company_desc, job_desc,
job_requirement, salary, location, employment_type,
department):
df = pd.DataFrame(columns=indep_cols)
df.loc[len(df)] = [job_title, company_name, company_desc, job_desc,
job_requirement, salary, location, employment_type,
department]
for column in df.columns:
df[column] = label_encoder.fit_transform(df[column])
t_indep = tensor(df[indep_cols].values, dtype=torch.float)
vals,indices = t_indep.max(dim=0)
t_indep = t_indep / vals
# return calc_preds(coeffs, t_indep)
return df.loc
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()