Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# ----------------------------
|
| 7 |
+
# CONFIG
|
| 8 |
+
# ----------------------------
|
| 9 |
+
JSON_URL = "https://file.notion.so/f/f/f86ed84d-b33c-4dfb-b0e0-97c5661516a3/3ed586a1-78e7-46af-9cf1-0961f95b5109/form-submissions-1.json?table=block&id=18a5392c-c93e-8054-b617-eb2a1a213d6c&spaceId=f86ed84d-b33c-4dfb-b0e0-97c5661516a3&expirationTimestamp=1758932214635&signature=sq1Jw2w3WoKIVMc8X078LO4SbfViD9ppdO0VXZ72Nro&downloadName=form-submissions.json"
|
| 10 |
+
|
| 11 |
+
MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
|
| 12 |
+
|
| 13 |
+
# Access Hugging Face secret in Spaces
|
| 14 |
+
import os
|
| 15 |
+
HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
|
| 16 |
+
if not HF_API_TOKEN:
|
| 17 |
+
raise ValueError("HF_API_TOKEN not found in environment. Add it in Space Secrets.")
|
| 18 |
+
|
| 19 |
+
# ----------------------------
|
| 20 |
+
# CATEGORIES DEFINED BY JOB TITLES
|
| 21 |
+
# ----------------------------
|
| 22 |
+
CATEGORIES = {
|
| 23 |
+
"AI": [
|
| 24 |
+
"AI/ML Ops Engineer","Senior Machine Learning Engineer","Principal Data Scientist",
|
| 25 |
+
"Senior Data Scientist","Machine Learning Research Scientist","Senior AI/ML Engineer",
|
| 26 |
+
"AI/ML Engineer","Big Data Engineer","AI Research Scientist","AI Research Analyst Consultant",
|
| 27 |
+
"AI Analyst","Senior Data Analyst","Automation Engineer","Senior Data Engineer",
|
| 28 |
+
"Machine Learning Engineer","Data Engineer","Data Scientist","Data Analyst"
|
| 29 |
+
],
|
| 30 |
+
"Marketing": [
|
| 31 |
+
"Marketing Specialist","Sales Agent","Salesman","Sales Associate"
|
| 32 |
+
],
|
| 33 |
+
"CTO": [
|
| 34 |
+
"Chief Technology Officer","CTO"
|
| 35 |
+
],
|
| 36 |
+
"Legal": [
|
| 37 |
+
"Legal Specialist","Attorney","Legal Intern","Lawyer"
|
| 38 |
+
],
|
| 39 |
+
"Finance": [
|
| 40 |
+
"Financial Analyst","Financial Advisor"
|
| 41 |
+
]
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
# ----------------------------
|
| 45 |
+
# HELPER FUNCTIONS
|
| 46 |
+
# ----------------------------
|
| 47 |
+
def fetch_json(url):
|
| 48 |
+
resp = requests.get(url)
|
| 49 |
+
resp.raise_for_status()
|
| 50 |
+
return resp.json()
|
| 51 |
+
|
| 52 |
+
def call_zephyr(prompt):
|
| 53 |
+
headers = {
|
| 54 |
+
"Authorization": f"Bearer {HF_API_TOKEN}",
|
| 55 |
+
"Content-Type": "application/json"
|
| 56 |
+
}
|
| 57 |
+
payload = {"inputs": prompt}
|
| 58 |
+
response = requests.post(
|
| 59 |
+
f"https://api-inference.huggingface.co/models/{MODEL_ID}",
|
| 60 |
+
headers=headers,
|
| 61 |
+
data=json.dumps(payload),
|
| 62 |
+
timeout=60
|
| 63 |
+
)
|
| 64 |
+
if response.status_code != 200:
|
| 65 |
+
return f"Zephyr API error: {response.text}"
|
| 66 |
+
result = response.json()
|
| 67 |
+
if isinstance(result, dict) and "error" in result:
|
| 68 |
+
return f"Zephyr API error: {result['error']}"
|
| 69 |
+
return result[0].get("generated_text", "")
|
| 70 |
+
|
| 71 |
+
def get_candidates_by_category(category_name, job_titles):
|
| 72 |
+
data = fetch_json(JSON_URL)
|
| 73 |
+
candidates = []
|
| 74 |
+
for person in data:
|
| 75 |
+
work_exps = person.get("work_experiences", [])
|
| 76 |
+
if len(work_exps) == 0:
|
| 77 |
+
continue
|
| 78 |
+
if any("full stack developer" in exp.get("roleName","").lower() for exp in work_exps):
|
| 79 |
+
continue
|
| 80 |
+
|
| 81 |
+
prompt = f"""
|
| 82 |
+
You are an HR assistant. Determine if the following candidate is suitable for the category '{category_name}'.
|
| 83 |
+
The category is defined by the job titles: {job_titles}
|
| 84 |
+
|
| 85 |
+
Candidate JSON: {json.dumps(person)}
|
| 86 |
+
|
| 87 |
+
Respond only 'Yes' or 'No'.
|
| 88 |
+
"""
|
| 89 |
+
llm_response = call_zephyr(prompt)
|
| 90 |
+
if llm_response and "Yes" in llm_response:
|
| 91 |
+
candidates.append({
|
| 92 |
+
"Name": person.get("name"),
|
| 93 |
+
"Email": person.get("email"),
|
| 94 |
+
"Phone": person.get("phone"),
|
| 95 |
+
"Location": person.get("location"),
|
| 96 |
+
"Roles": ", ".join([exp.get("roleName") for exp in work_exps]),
|
| 97 |
+
"Skills": ", ".join(person.get("skills", [])),
|
| 98 |
+
"Salary": person.get("annual_salary_expectation", {}).get("full-time", "N/A")
|
| 99 |
+
})
|
| 100 |
+
if len(candidates) == 0:
|
| 101 |
+
return f"No suitable candidates found for {category_name}."
|
| 102 |
+
return pd.DataFrame(candidates)
|
| 103 |
+
|
| 104 |
+
# ----------------------------
|
| 105 |
+
# GRADIO INTERFACE
|
| 106 |
+
# ----------------------------
|
| 107 |
+
def run_dashboard(category):
|
| 108 |
+
if category not in CATEGORIES:
|
| 109 |
+
return f"Category {category} not found."
|
| 110 |
+
df = get_candidates_by_category(category, CATEGORIES[category])
|
| 111 |
+
return df
|
| 112 |
+
|
| 113 |
+
category_options = list(CATEGORIES.keys())
|
| 114 |
+
|
| 115 |
+
demo = gr.Interface(
|
| 116 |
+
fn=run_dashboard,
|
| 117 |
+
inputs=gr.Dropdown(category_options, label="Select Category"),
|
| 118 |
+
outputs=gr.Dataframe(label="Suitable Candidates"),
|
| 119 |
+
live=False,
|
| 120 |
+
title="Startup Candidate Dashboard - Zephyr-7B-Beta"
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
if __name__ == "__main__":
|
| 124 |
+
demo.launch()
|