Infinity-1995 commited on
Commit
a57db7e
·
verified ·
1 Parent(s): 3e9d9d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -25
app.py CHANGED
@@ -1,34 +1,62 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
 
 
3
 
4
- # App title
5
- st.set_page_config(page_title="Fake Job Detector", page_icon="🕵️‍♂️")
6
- st.title("Fake Job / Lie Detector")
7
- st.markdown("Enter a job description and check if it seems suspicious!")
8
-
9
- # Load small NLI model for zero-shot classification (CPU-friendly)
10
  @st.cache_resource
11
- def load_model():
12
- return pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- classifier = load_model()
 
15
 
16
- # Input from user
17
- job_description = st.text_area("Enter the job description:")
18
 
19
- # Label options
20
- labels = ["Legitimate", "Suspicious", "Fake", "Scam"]
 
 
 
 
 
 
 
 
 
 
21
 
22
- # Button to check
23
- if st.button("Check Job"):
24
- if not job_description.strip():
25
- st.warning("Please enter a job description!")
26
  else:
27
- # Run zero-shot classification
28
- results = classifier(job_description, candidate_labels=labels)
29
- st.subheader("Prediction:")
30
- # Show top label and scores
31
- top_label = results["labels"][0]
32
- score = results["scores"][0]
33
- st.success(f"Most likely: **{top_label}** ({score*100:.2f}%)")
34
- st.write("Full results:", results)
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ from PIL import Image
4
+ import pytesseract
5
+ from pdf2image import convert_from_bytes
6
 
7
+ # -------------------
8
+ # Load Hugging Face text classifier
9
+ # -------------------
 
 
 
10
  @st.cache_resource
11
+ def load_classifier():
12
+ classifier = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
13
+ return classifier
14
+
15
+ classifier = load_classifier()
16
+
17
+ # -------------------
18
+ # App UI
19
+ # -------------------
20
+ st.title("Fake Job Detector")
21
+ st.write("Paste job text or upload a screenshot/PDF to check if the job posting is Legitimate or Fake.")
22
+
23
+ # Job text input
24
+ job_text = st.text_area("Paste job description here:")
25
 
26
+ # File upload (image or PDF)
27
+ uploaded_file = st.file_uploader("Or upload a screenshot / PDF", type=["png","jpg","jpeg","pdf"])
28
 
29
+ extracted_text = ""
 
30
 
31
+ # Extract text from file if uploaded
32
+ if uploaded_file:
33
+ if uploaded_file.type == "application/pdf":
34
+ images = convert_from_bytes(uploaded_file.read())
35
+ for img in images:
36
+ extracted_text += pytesseract.image_to_string(img) + "\n"
37
+ else:
38
+ img = Image.open(uploaded_file)
39
+ extracted_text = pytesseract.image_to_string(img)
40
+
41
+ # Combine pasted text + extracted text
42
+ full_text = job_text + "\n" + extracted_text
43
 
44
+ if st.button("Detect"):
45
+ if full_text.strip() == "":
46
+ st.warning("Please paste job text or upload a file!")
 
47
  else:
48
+ result = classifier(full_text)
49
+ label = result[0]['label']
50
+ score = result[0]['score']
51
+
52
+ # Map labels to Fake/Suspicious/Legit (simple demo)
53
+ # Here using SST-2 labels for demo; in real app, fine-tune model
54
+ if label == "NEGATIVE":
55
+ final_label = "Suspicious / Fake"
56
+ else:
57
+ final_label = "Legitimate"
58
+
59
+ st.success(f"Prediction: **{final_label}**")
60
+ st.info(f"Confidence: {score:.2f}")
61
+ st.subheader("Extracted Job Text:")
62
+ st.text_area("Text Extracted", full_text, height=200)