Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +2 -8
- app.py +214 -0
- rajan/Profile.pdf +0 -0
- rajan/resume.pdf +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
rajan/resume.pdf filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: ResumeAI
|
| 3 |
-
emoji: 📚
|
| 4 |
-
colorFrom: red
|
| 5 |
-
colorTo: yellow
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 6.9.0
|
| 8 |
app_file: app.py
|
| 9 |
-
|
|
|
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: ResumeAI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app_file: app.py
|
| 4 |
+
sdk: gradio
|
| 5 |
+
sdk_version: 5.49.1
|
| 6 |
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# imports
|
| 2 |
+
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import requests
|
| 8 |
+
from pypdf import PdfReader
|
| 9 |
+
import gradio as gr
|
| 10 |
+
# The usual start
|
| 11 |
+
|
| 12 |
+
load_dotenv(override=True)
|
| 13 |
+
gemini = OpenAI(
|
| 14 |
+
api_key=os.getenv("GOOGLE_API_KEY"),
|
| 15 |
+
base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# %%
|
| 19 |
+
# For pushover
|
| 20 |
+
|
| 21 |
+
pushover_user = os.getenv("PUSHOVER_USER")
|
| 22 |
+
pushover_token = os.getenv("PUSHOVER_TOKEN")
|
| 23 |
+
pushover_url = "https://api.pushover.net/1/messages.json"
|
| 24 |
+
|
| 25 |
+
if pushover_user:
|
| 26 |
+
print(f"Pushover user found and starts with {pushover_user[0]}")
|
| 27 |
+
else:
|
| 28 |
+
print("Pushover user not found")
|
| 29 |
+
|
| 30 |
+
if pushover_token:
|
| 31 |
+
print(f"Pushover token found and starts with {pushover_token[0]}")
|
| 32 |
+
else:
|
| 33 |
+
print("Pushover token not found")
|
| 34 |
+
|
| 35 |
+
# %%
|
| 36 |
+
def push(message):
|
| 37 |
+
print(f"Push: {message}")
|
| 38 |
+
payload = {"user": pushover_user, "token": pushover_token, "message": message}
|
| 39 |
+
requests.post(pushover_url, data=payload)
|
| 40 |
+
|
| 41 |
+
# %%
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# %%
|
| 45 |
+
def tool_user_details(email, name="Name not provided", notes="not provided"):
|
| 46 |
+
push(f"Interest from {name} with email {email} and notes {notes}")
|
| 47 |
+
return {"response": "ok"}
|
| 48 |
+
|
| 49 |
+
# %%
|
| 50 |
+
def tool_unknown_question(question):
|
| 51 |
+
push(f"Question I couldn't answer: {question} ")
|
| 52 |
+
return {"response": "ok"}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# %%
|
| 57 |
+
def tool_resume_question(question, email):
|
| 58 |
+
push(f"Resume request on {email}, Message: {question}")
|
| 59 |
+
return {"response": "ok"}
|
| 60 |
+
|
| 61 |
+
# %%
|
| 62 |
+
tool_user_details_json = {
|
| 63 |
+
"name": "tool_user_details",
|
| 64 |
+
"description": "Use this tool to record that a user is interested in being in touch and provided an email address",
|
| 65 |
+
"parameters": {
|
| 66 |
+
"type": "object",
|
| 67 |
+
"properties": {
|
| 68 |
+
"email": {
|
| 69 |
+
"type": "string",
|
| 70 |
+
"description": "The email address of this user"
|
| 71 |
+
},
|
| 72 |
+
"name": {
|
| 73 |
+
"type": "string",
|
| 74 |
+
"description": "The user's name, if they provided it"
|
| 75 |
+
}
|
| 76 |
+
,
|
| 77 |
+
"notes": {
|
| 78 |
+
"type": "string",
|
| 79 |
+
"description": "Any additional information about the conversation that's worth recording to give context"
|
| 80 |
+
},
|
| 81 |
+
},
|
| 82 |
+
"required": ["email"],
|
| 83 |
+
"additionalProperties": False
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
# %%
|
| 88 |
+
tool_unknown_question_json = {
|
| 89 |
+
"name": "tool_unknown_question",
|
| 90 |
+
"description": "Always use this tool to record any question that couldn't be answered as you didn't know the answer, but tell user you don't know the answer at the moment and suggest to get in touch on my email.",
|
| 91 |
+
"parameters": {
|
| 92 |
+
"type": "object",
|
| 93 |
+
"properties": {
|
| 94 |
+
"question": {
|
| 95 |
+
"type": "string",
|
| 96 |
+
"description": "The question that couldn't be answered. Keep same verbiage as user's request"
|
| 97 |
+
},
|
| 98 |
+
},
|
| 99 |
+
"required": ["question"],
|
| 100 |
+
"additionalProperties": False
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
# %%
|
| 105 |
+
tool_resume_question_json = {
|
| 106 |
+
"name": "tool_resume_question",
|
| 107 |
+
"description": "Always use this tool to record that a user needs a copy of resume and also tell them that resume will be sent soon to your email address",
|
| 108 |
+
"parameters": {
|
| 109 |
+
"type": "object",
|
| 110 |
+
"properties": {
|
| 111 |
+
"question": {
|
| 112 |
+
"type": "string",
|
| 113 |
+
"description": "Resume Request from the user. Keep same verbiage as user's request"
|
| 114 |
+
},
|
| 115 |
+
"email": {
|
| 116 |
+
"type": "string",
|
| 117 |
+
"description": "The email address of this user"
|
| 118 |
+
},
|
| 119 |
+
},
|
| 120 |
+
"required": ["email"],
|
| 121 |
+
"additionalProperties": False
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
# %%
|
| 126 |
+
tools = [{"type": "function", "function": tool_user_details_json},
|
| 127 |
+
{"type": "function", "function": tool_unknown_question_json},
|
| 128 |
+
{"type": "function", "function": tool_resume_question_json}]
|
| 129 |
+
|
| 130 |
+
# %%
|
| 131 |
+
tools
|
| 132 |
+
|
| 133 |
+
# %%
|
| 134 |
+
# This is a more elegant way that avoids the IF statement.
|
| 135 |
+
|
| 136 |
+
def handle_tool_calls(tool_calls):
|
| 137 |
+
results = []
|
| 138 |
+
for tool_call in tool_calls:
|
| 139 |
+
print(tool_call)
|
| 140 |
+
tool_name = tool_call.function.name
|
| 141 |
+
arguments = json.loads(tool_call.function.arguments)
|
| 142 |
+
print(f"Tool called: {tool_name}", flush=True)
|
| 143 |
+
tool = globals().get(tool_name)
|
| 144 |
+
result = tool(**arguments,) if tool else {}
|
| 145 |
+
results.append({"role": "tool","content": json.dumps(result),"tool_call_id": tool_call.id})
|
| 146 |
+
return results
|
| 147 |
+
|
| 148 |
+
# %%
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# %%
|
| 152 |
+
reader = PdfReader("rajan/profile.pdf")
|
| 153 |
+
linkedin = ""
|
| 154 |
+
for page in reader.pages:
|
| 155 |
+
text = page.extract_text()
|
| 156 |
+
if text:
|
| 157 |
+
linkedin += text
|
| 158 |
+
|
| 159 |
+
reader = PdfReader("rajan/resume.pdf")
|
| 160 |
+
resume ="";
|
| 161 |
+
|
| 162 |
+
for page in reader.pages:
|
| 163 |
+
text = page.extract_text()
|
| 164 |
+
if text:
|
| 165 |
+
resume += text
|
| 166 |
+
|
| 167 |
+
name = "Rajan Panchal"
|
| 168 |
+
|
| 169 |
+
# %%
|
| 170 |
+
system_prompt = f"You are acting as {name}. You are answering questions on {name}'s website, \
|
| 171 |
+
particularly questions related to {name}'s career, background, skills and experience. \
|
| 172 |
+
Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \
|
| 173 |
+
You are given a resume of {name}'s and LinkedIn profile which you can use to answer questions. \
|
| 174 |
+
Be professional and engaging, as if talking to a potential client or future employer who came across the website. \
|
| 175 |
+
First let user know what all information you can provide and also tell user that if they need resume they can request by giving their email\
|
| 176 |
+
If you don't know the answer to any question, use your tool_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. \
|
| 177 |
+
If the user is engaging in discussion, try to steer them towards getting in touch via email; ask for their email and record it using your tool_user_details tool. \
|
| 178 |
+
If user request for resume copy, ask user for email and use tool_resume_request tool to send resume request."
|
| 179 |
+
|
| 180 |
+
system_prompt += f"\n\n## Summary:\n{resume}\n\n## LinkedIn Profile:\n{linkedin}\n\n"
|
| 181 |
+
system_prompt += f"With this context, please chat with the user, always staying in character as {name}."
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
# %%
|
| 185 |
+
def chat(message, history):
|
| 186 |
+
messages = [{"role": "system", "content": system_prompt}] + history + [{"role": "user", "content": message}]
|
| 187 |
+
done = False
|
| 188 |
+
while not done:
|
| 189 |
+
|
| 190 |
+
# This is the call to the LLM - see that we pass in the tools json
|
| 191 |
+
|
| 192 |
+
response = gemini.chat.completions.create(model="gemini-2.5-flash", messages=messages, tools=tools)
|
| 193 |
+
|
| 194 |
+
finish_reason = response.choices[0].finish_reason
|
| 195 |
+
|
| 196 |
+
# If the LLM wants to call a tool, we do that!
|
| 197 |
+
|
| 198 |
+
if finish_reason=="tool_calls":
|
| 199 |
+
message = response.choices[0].message
|
| 200 |
+
tool_calls = message.tool_calls
|
| 201 |
+
results = handle_tool_calls(tool_calls)
|
| 202 |
+
messages.append(message)
|
| 203 |
+
messages.extend(results)
|
| 204 |
+
else:
|
| 205 |
+
done = True
|
| 206 |
+
return response.choices[0].message.content
|
| 207 |
+
|
| 208 |
+
# %%
|
| 209 |
+
gr.ChatInterface(chat, type="messages",title="Rajan AI – Interactive Resume").launch()
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
#
|
rajan/Profile.pdf
ADDED
|
Binary file (56.1 kB). View file
|
|
|
rajan/resume.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:20aa3d6e94133380855e8526ac6bec04b6c338e17b6586473af46fba8babf673
|
| 3 |
+
size 226599
|