Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import json
|
| 5 |
-
import
|
|
|
|
| 6 |
|
| 7 |
# ----------------------------
|
| 8 |
# CONFIG
|
| 9 |
# ----------------------------
|
| 10 |
-
|
| 11 |
-
|
| 12 |
MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
|
| 13 |
|
| 14 |
-
|
| 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.")
|
|
@@ -44,10 +43,9 @@ CATEGORIES = {
|
|
| 44 |
# ----------------------------
|
| 45 |
# HELPER FUNCTIONS
|
| 46 |
# ----------------------------
|
| 47 |
-
def
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
return resp.json()
|
| 51 |
|
| 52 |
def call_zephyr(prompt):
|
| 53 |
headers = {
|
|
@@ -69,7 +67,7 @@ def call_zephyr(prompt):
|
|
| 69 |
return result[0].get("generated_text", "")
|
| 70 |
|
| 71 |
def get_candidates_by_category(category_name, job_titles):
|
| 72 |
-
data =
|
| 73 |
candidates = []
|
| 74 |
for person in data:
|
| 75 |
work_exps = person.get("work_experiences", [])
|
|
@@ -99,35 +97,31 @@ Respond only 'Yes' or 'No'.
|
|
| 99 |
})
|
| 100 |
|
| 101 |
if len(candidates) == 0:
|
| 102 |
-
return pd.DataFrame()
|
| 103 |
|
| 104 |
df = pd.DataFrame(candidates)
|
| 105 |
-
|
| 106 |
-
csv_buffer = io.BytesIO()
|
| 107 |
-
df.to_csv(csv_buffer, index=False)
|
| 108 |
-
csv_buffer.seek(0)
|
| 109 |
-
return df, ("candidates.csv", csv_buffer.read())
|
| 110 |
|
| 111 |
# ----------------------------
|
| 112 |
# GRADIO INTERFACE
|
| 113 |
# ----------------------------
|
| 114 |
def run_dashboard(category):
|
| 115 |
if category not in CATEGORIES:
|
| 116 |
-
return
|
| 117 |
-
df
|
| 118 |
if df.empty:
|
| 119 |
-
return
|
| 120 |
-
return df
|
| 121 |
|
| 122 |
category_options = list(CATEGORIES.keys())
|
| 123 |
|
| 124 |
demo = gr.Interface(
|
| 125 |
fn=run_dashboard,
|
| 126 |
inputs=gr.Dropdown(category_options, label="Select Category"),
|
| 127 |
-
outputs=
|
| 128 |
live=False,
|
| 129 |
title="Startup Candidate Dashboard - Zephyr-7B-Beta",
|
| 130 |
-
description="Select a category to view suitable candidates.
|
| 131 |
)
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
+
import os
|
| 5 |
+
import requests
|
| 6 |
|
| 7 |
# ----------------------------
|
| 8 |
# CONFIG
|
| 9 |
# ----------------------------
|
| 10 |
+
JSON_FILE = "form-submissions-1.json" # local JSON file in the Space
|
|
|
|
| 11 |
MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
|
| 12 |
|
| 13 |
+
# Hugging Face token from Space Secrets
|
| 14 |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
|
| 15 |
if not HF_API_TOKEN:
|
| 16 |
raise ValueError("HF_API_TOKEN not found in environment. Add it in Space Secrets.")
|
|
|
|
| 43 |
# ----------------------------
|
| 44 |
# HELPER FUNCTIONS
|
| 45 |
# ----------------------------
|
| 46 |
+
def fetch_json_local(file_path):
|
| 47 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 48 |
+
return json.load(f)
|
|
|
|
| 49 |
|
| 50 |
def call_zephyr(prompt):
|
| 51 |
headers = {
|
|
|
|
| 67 |
return result[0].get("generated_text", "")
|
| 68 |
|
| 69 |
def get_candidates_by_category(category_name, job_titles):
|
| 70 |
+
data = fetch_json_local(JSON_FILE)
|
| 71 |
candidates = []
|
| 72 |
for person in data:
|
| 73 |
work_exps = person.get("work_experiences", [])
|
|
|
|
| 97 |
})
|
| 98 |
|
| 99 |
if len(candidates) == 0:
|
| 100 |
+
return pd.DataFrame()
|
| 101 |
|
| 102 |
df = pd.DataFrame(candidates)
|
| 103 |
+
return df
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
# ----------------------------
|
| 106 |
# GRADIO INTERFACE
|
| 107 |
# ----------------------------
|
| 108 |
def run_dashboard(category):
|
| 109 |
if category not in CATEGORIES:
|
| 110 |
+
return pd.DataFrame()
|
| 111 |
+
df = get_candidates_by_category(category, CATEGORIES[category])
|
| 112 |
if df.empty:
|
| 113 |
+
return pd.DataFrame()
|
| 114 |
+
return df
|
| 115 |
|
| 116 |
category_options = list(CATEGORIES.keys())
|
| 117 |
|
| 118 |
demo = gr.Interface(
|
| 119 |
fn=run_dashboard,
|
| 120 |
inputs=gr.Dropdown(category_options, label="Select Category"),
|
| 121 |
+
outputs=gr.Dataframe(label="Suitable Candidates"),
|
| 122 |
live=False,
|
| 123 |
title="Startup Candidate Dashboard - Zephyr-7B-Beta",
|
| 124 |
+
description="Select a category to view suitable candidates."
|
| 125 |
)
|
| 126 |
|
| 127 |
if __name__ == "__main__":
|