curiouscurrent commited on
Commit
4392910
·
verified ·
1 Parent(s): 1562ed3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -22
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 io
 
6
 
7
  # ----------------------------
8
  # CONFIG
9
  # ----------------------------
10
- 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"
11
-
12
  MODEL_ID = "HuggingFaceH4/zephyr-7b-beta"
13
 
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.")
@@ -44,10 +43,9 @@ CATEGORIES = {
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 = {
@@ -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 = fetch_json(JSON_URL)
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(), None
103
 
104
  df = pd.DataFrame(candidates)
105
- # Convert to CSV as bytes and provide filename for Gradio
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 f"Category {category} not found.", None
117
- df, csv_file = get_candidates_by_category(category, CATEGORIES[category])
118
  if df.empty:
119
- return f"No suitable candidates found for {category}.", None
120
- return df, csv_file
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=[gr.Dataframe(label="Suitable Candidates"), gr.File(label="Download CSV")],
128
  live=False,
129
  title="Startup Candidate Dashboard - Zephyr-7B-Beta",
130
- description="Select a category to view suitable candidates. You can also download the results as CSV."
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__":