Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,9 @@ import os
|
|
| 5 |
import requests
|
| 6 |
from functools import lru_cache
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
JSON_FILE = "form-submissions-1.json"
|
| 9 |
MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
|
| 10 |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
|
|
@@ -31,9 +34,6 @@ CATEGORIES = {
|
|
| 31 |
# ----------------------------
|
| 32 |
@lru_cache(maxsize=512)
|
| 33 |
def call_zephyr_cached(candidate_str, category_name, job_titles_tuple):
|
| 34 |
-
"""
|
| 35 |
-
Cached Zephyr LLM call.
|
| 36 |
-
"""
|
| 37 |
try:
|
| 38 |
prompt = f"""
|
| 39 |
You are an HR assistant. Review this candidate and determine if they are suitable for the category '{category_name}'.
|
|
@@ -43,10 +43,7 @@ Candidate JSON: {candidate_str}
|
|
| 43 |
|
| 44 |
Respond only 'Yes' if suitable, otherwise 'No'.
|
| 45 |
"""
|
| 46 |
-
headers = {
|
| 47 |
-
"Authorization": f"Bearer {HF_API_TOKEN}",
|
| 48 |
-
"Content-Type": "application/json"
|
| 49 |
-
}
|
| 50 |
payload = {"inputs": prompt}
|
| 51 |
response = requests.post(
|
| 52 |
f"https://api-inference.huggingface.co/models/{MODEL_ID}",
|
|
@@ -110,31 +107,43 @@ def get_top_candidates(category_name, job_titles, top_n=5):
|
|
| 110 |
df = df.sort_values("Salary_sort").drop(columns=["Salary_sort"])
|
| 111 |
return df.head(top_n)
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
# ----------------------------
|
| 114 |
# Gradio interface
|
| 115 |
# ----------------------------
|
| 116 |
def run_dashboard(category):
|
| 117 |
if category not in CATEGORIES:
|
| 118 |
-
return pd.DataFrame()
|
| 119 |
-
df = get_top_candidates(category, CATEGORIES[category], top_n=5)
|
| 120 |
-
return df
|
| 121 |
-
|
| 122 |
-
def download_csv(category):
|
| 123 |
df = get_top_candidates(category, CATEGORIES[category], top_n=5)
|
| 124 |
if df.empty:
|
| 125 |
-
return None
|
| 126 |
file_path = "/tmp/outputs.csv"
|
| 127 |
df.to_csv(file_path, index=False)
|
| 128 |
-
return file_path
|
| 129 |
|
| 130 |
demo = gr.Interface(
|
| 131 |
fn=run_dashboard,
|
| 132 |
inputs=gr.Dropdown(list(CATEGORIES.keys()), label="Select Category"),
|
| 133 |
outputs=[gr.Dataframe(label="Top 5 Recommended Candidates"),
|
| 134 |
-
gr.File(label="Download CSV"
|
| 135 |
title="Startup Candidate Dashboard - Zephyr-7B-Beta",
|
| 136 |
-
description="Top 5 candidates per category using Zephyr LLM
|
| 137 |
)
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
if __name__ == "__main__":
|
| 140 |
-
|
|
|
|
| 5 |
import requests
|
| 6 |
from functools import lru_cache
|
| 7 |
|
| 8 |
+
# ----------------------------
|
| 9 |
+
# CONFIG
|
| 10 |
+
# ----------------------------
|
| 11 |
JSON_FILE = "form-submissions-1.json"
|
| 12 |
MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
|
| 13 |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
|
|
|
|
| 34 |
# ----------------------------
|
| 35 |
@lru_cache(maxsize=512)
|
| 36 |
def call_zephyr_cached(candidate_str, category_name, job_titles_tuple):
|
|
|
|
|
|
|
|
|
|
| 37 |
try:
|
| 38 |
prompt = f"""
|
| 39 |
You are an HR assistant. Review this candidate and determine if they are suitable for the category '{category_name}'.
|
|
|
|
| 43 |
|
| 44 |
Respond only 'Yes' if suitable, otherwise 'No'.
|
| 45 |
"""
|
| 46 |
+
headers = {"Authorization": f"Bearer {HF_API_TOKEN}", "Content-Type": "application/json"}
|
|
|
|
|
|
|
|
|
|
| 47 |
payload = {"inputs": prompt}
|
| 48 |
response = requests.post(
|
| 49 |
f"https://api-inference.huggingface.co/models/{MODEL_ID}",
|
|
|
|
| 107 |
df = df.sort_values("Salary_sort").drop(columns=["Salary_sort"])
|
| 108 |
return df.head(top_n)
|
| 109 |
|
| 110 |
+
# ----------------------------
|
| 111 |
+
# Show first 5 candidates from raw JSON
|
| 112 |
+
# ----------------------------
|
| 113 |
+
def show_first_candidates():
|
| 114 |
+
data = json.load(open(JSON_FILE, encoding="utf-8"))
|
| 115 |
+
first_5 = data[:5]
|
| 116 |
+
df = pd.DataFrame(first_5)
|
| 117 |
+
return df
|
| 118 |
+
|
| 119 |
# ----------------------------
|
| 120 |
# Gradio interface
|
| 121 |
# ----------------------------
|
| 122 |
def run_dashboard(category):
|
| 123 |
if category not in CATEGORIES:
|
| 124 |
+
return pd.DataFrame(), None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
df = get_top_candidates(category, CATEGORIES[category], top_n=5)
|
| 126 |
if df.empty:
|
| 127 |
+
return df, None
|
| 128 |
file_path = "/tmp/outputs.csv"
|
| 129 |
df.to_csv(file_path, index=False)
|
| 130 |
+
return df, file_path
|
| 131 |
|
| 132 |
demo = gr.Interface(
|
| 133 |
fn=run_dashboard,
|
| 134 |
inputs=gr.Dropdown(list(CATEGORIES.keys()), label="Select Category"),
|
| 135 |
outputs=[gr.Dataframe(label="Top 5 Recommended Candidates"),
|
| 136 |
+
gr.File(label="Download CSV")],
|
| 137 |
title="Startup Candidate Dashboard - Zephyr-7B-Beta",
|
| 138 |
+
description="Top 5 candidates per category using Zephyr LLM. Download CSV available."
|
| 139 |
)
|
| 140 |
|
| 141 |
+
# Add separate interface to show first 5 raw candidates
|
| 142 |
+
with gr.Blocks() as app:
|
| 143 |
+
gr.Markdown("### Raw JSON Preview: First 5 Candidates")
|
| 144 |
+
gr.Dataframe(show_first_candidates(), label="First 5 Candidates from JSON")
|
| 145 |
+
gr.Markdown("---")
|
| 146 |
+
demo.render()
|
| 147 |
+
|
| 148 |
if __name__ == "__main__":
|
| 149 |
+
app.launch()
|