Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,113 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def analyze(text):
|
| 4 |
-
return "No discrimination detected"
|
| 5 |
|
| 6 |
demo = gr.Interface(
|
| 7 |
fn=analyze,
|
| 8 |
-
inputs=gr.Textbox(
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
|
|
|
|
|
|
|
| 13 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
# -----------------------------
|
| 5 |
+
# Discrimination keyword rules
|
| 6 |
+
# -----------------------------
|
| 7 |
+
|
| 8 |
+
discrimination_rules = {
|
| 9 |
+
|
| 10 |
+
"Gender Discrimination": [
|
| 11 |
+
"male only",
|
| 12 |
+
"female only",
|
| 13 |
+
"waitress",
|
| 14 |
+
"waiter",
|
| 15 |
+
"salesman",
|
| 16 |
+
"saleswoman",
|
| 17 |
+
"young lady"
|
| 18 |
+
],
|
| 19 |
+
|
| 20 |
+
"Age Discrimination": [
|
| 21 |
+
"young",
|
| 22 |
+
"under 30",
|
| 23 |
+
"under 35",
|
| 24 |
+
"recent graduate",
|
| 25 |
+
"junior only",
|
| 26 |
+
"age limit"
|
| 27 |
+
],
|
| 28 |
+
|
| 29 |
+
"Nationality Discrimination": [
|
| 30 |
+
"italian only",
|
| 31 |
+
"eu nationals only",
|
| 32 |
+
"native english speaker",
|
| 33 |
+
"must be italian",
|
| 34 |
+
"only european"
|
| 35 |
+
],
|
| 36 |
+
|
| 37 |
+
"Religion Discrimination": [
|
| 38 |
+
"christian only",
|
| 39 |
+
"muslim only"
|
| 40 |
+
],
|
| 41 |
+
|
| 42 |
+
"Disability Discrimination": [
|
| 43 |
+
"able bodied",
|
| 44 |
+
"physically fit only"
|
| 45 |
+
]
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# -----------------------------
|
| 50 |
+
# Text cleaning
|
| 51 |
+
# -----------------------------
|
| 52 |
+
|
| 53 |
+
def clean_text(text):
|
| 54 |
+
|
| 55 |
+
text = str(text).lower()
|
| 56 |
+
text = re.sub(r"[^\w\s]", "", text)
|
| 57 |
+
|
| 58 |
+
return text
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# -----------------------------
|
| 62 |
+
# Detection function
|
| 63 |
+
# -----------------------------
|
| 64 |
+
|
| 65 |
+
def detect_discrimination(text):
|
| 66 |
+
|
| 67 |
+
text = clean_text(text)
|
| 68 |
+
|
| 69 |
+
categories = []
|
| 70 |
+
keywords = []
|
| 71 |
+
|
| 72 |
+
for category, words in discrimination_rules.items():
|
| 73 |
+
|
| 74 |
+
for word in words:
|
| 75 |
+
|
| 76 |
+
if word in text:
|
| 77 |
+
categories.append(category)
|
| 78 |
+
keywords.append(word)
|
| 79 |
+
|
| 80 |
+
if len(categories) == 0:
|
| 81 |
+
return "✅ No discrimination detected", "None"
|
| 82 |
+
|
| 83 |
+
return ", ".join(set(categories)), ", ".join(set(keywords))
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# -----------------------------
|
| 87 |
+
# Gradio Interface
|
| 88 |
+
# -----------------------------
|
| 89 |
+
|
| 90 |
+
def analyze(job_post):
|
| 91 |
+
|
| 92 |
+
category, keywords = detect_discrimination(job_post)
|
| 93 |
+
|
| 94 |
+
return category, keywords
|
| 95 |
|
|
|
|
|
|
|
| 96 |
|
| 97 |
demo = gr.Interface(
|
| 98 |
fn=analyze,
|
| 99 |
+
inputs=gr.Textbox(
|
| 100 |
+
lines=8,
|
| 101 |
+
placeholder="Paste the job advertisement text here..."
|
| 102 |
+
),
|
| 103 |
+
outputs=[
|
| 104 |
+
gr.Textbox(label="Detected Discrimination Type"),
|
| 105 |
+
gr.Textbox(label="Detected Keywords")
|
| 106 |
+
],
|
| 107 |
+
title="AI Job Post Discrimination Checker",
|
| 108 |
+
description="This tool analyzes job advertisements and flags possible discriminatory language."
|
| 109 |
)
|
| 110 |
|
| 111 |
+
|
| 112 |
+
# IMPORTANT for HuggingFace Spaces
|
| 113 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|