Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import json
|
|
@@ -6,14 +6,15 @@ import json
|
|
| 6 |
# ----------------------------
|
| 7 |
# CONFIG
|
| 8 |
# ----------------------------
|
| 9 |
-
st.set_page_config(page_title="Startup Candidate Dashboard", layout="wide")
|
| 10 |
-
|
| 11 |
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"
|
| 12 |
|
| 13 |
MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# ----------------------------
|
| 19 |
# CATEGORIES DEFINED BY JOB TITLES
|
|
@@ -61,24 +62,22 @@ def call_zephyr(prompt):
|
|
| 61 |
timeout=60
|
| 62 |
)
|
| 63 |
if response.status_code != 200:
|
| 64 |
-
|
| 65 |
-
return None
|
| 66 |
result = response.json()
|
| 67 |
if isinstance(result, dict) and "error" in result:
|
| 68 |
-
|
| 69 |
-
return None
|
| 70 |
return result[0].get("generated_text", "")
|
| 71 |
|
| 72 |
-
def get_candidates_by_category(
|
|
|
|
| 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 |
-
# Prepare prompt: ask Zephyr if this candidate matches any of the predefined job titles
|
| 82 |
prompt = f"""
|
| 83 |
You are an HR assistant. Determine if the following candidate is suitable for the category '{category_name}'.
|
| 84 |
The category is defined by the job titles: {job_titles}
|
|
@@ -87,35 +86,39 @@ Candidate JSON: {json.dumps(person)}
|
|
| 87 |
|
| 88 |
Respond only 'Yes' or 'No'.
|
| 89 |
"""
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
st.warning(f"Error processing {person.get('name')}: {e}")
|
| 104 |
return pd.DataFrame(candidates)
|
| 105 |
|
| 106 |
# ----------------------------
|
| 107 |
-
#
|
| 108 |
# ----------------------------
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
df = get_candidates_by_category(data, category_name, job_titles)
|
| 118 |
-
if df.empty:
|
| 119 |
-
st.write("No suitable candidates found.")
|
| 120 |
-
else:
|
| 121 |
-
st.dataframe(df)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import json
|
|
|
|
| 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
|
|
|
|
| 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}
|
|
|
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|