Spaces:
Sleeping
Sleeping
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' | |
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[0] = [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) | |
iface = gr.Interface( | |
fn=main, | |
inputs=[gr.Textbox(label="Job title"), gr.Textbox(label="Company name"), | |
gr.Textbox(label="Company description"), gr.Textbox(label="Job description"), | |
gr.Textbox(label="Job Requirements"), gr.Textbox(label="Salary"), | |
gr.Textbox(label="Location"), gr.Textbox(label="Employment Type"), | |
gr.Textbox(label="Department")], | |
outputs="text", | |
title="Job posting identifier", | |
description="Identifies job posts as real or fake" | |
) | |
iface.launch() | |