Spaces:
Build error
Build error
File size: 2,486 Bytes
6d8718a |
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 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import gradio as gr
import pytesseract
from PIL import Image
import requests
from bs4 import BeautifulSoup
# Load model
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Prediction function
def predict_job_post(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
prediction = torch.argmax(logits, dim=1).item()
prob = torch.nn.functional.softmax(logits, dim=1)[prediction].item()
if prediction == 1:
return f"π’ REAL Job (Confidence: {prob:.2f})\nReason: The post has positive and trustworthy language."
else:
return f"π΄ FAKE Job (Confidence: {prob:.2f})\nReason: The post uses negative or suspicious language patterns."
# OCR for image
def process_image(image):
text = pytesseract.image_to_string(image)
return predict_job_post(text)
# Scraper for URL
def process_url(url):
try:
response = requests.get(url, timeout=5)
soup = BeautifulSoup(response.text, 'html.parser')
text = soup.get_text(separator=' ', strip=True)
return predict_job_post(text[:1000])
except:
return "β Error: Could not fetch or process the URL."
# Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## π΅ββ Fake Job Detector AI App")
gr.Markdown("Input job description, image, or link to check if the job is real or fake.")
with gr.Tab("Text"):
text_input = gr.Textbox(lines=4, label="Enter Job Text")
text_output = gr.Textbox(label="Result")
text_button = gr.Button("Analyze Text")
text_button.click(fn=predict_job_post, inputs=text_input, outputs=text_output)
with gr.Tab("Image"):
image_input = gr.Image(type="pil", label="Upload Image")
image_output = gr.Textbox(label="Result")
image_button = gr.Button("Analyze Image")
image_button.click(fn=process_image, inputs=image_input, outputs=image_output)
with gr.Tab("URL"):
url_input = gr.Textbox(label="Paste Job Post URL")
url_output = gr.Textbox(label="Result")
url_button = gr.Button("Analyze URL")
url_button.click(fn=process_url, inputs=url_input, outputs=url_output)
demo.launch() |