Spaces:
Sleeping
Sleeping
Download app.py from MichaelAfolami/Career_Guide: direct link, hf CLI and curl.
- Browser
- Download file 14.2 kB
-
https://huggingface.co/spaces/MichaelAfolami/Career_Guide/resolve/main/app.py
- Command line
-
hf download hf://spaces/MichaelAfolami/Career_Guide/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MichaelAfolami/Career_Guide/resolve/main/app.py
14.2 kB
| from dotenv import load_dotenv | |
| from openai import OpenAI | |
| import json | |
| import os | |
| os.environ["PYTHONUNBUFFERED"] = "1" | |
| import requests | |
| from pypdf import PdfReader | |
| import gradio as gr | |
| load_dotenv(override=True) | |
| def push(text): | |
| requests.post( | |
| "https://api.pushover.net/1/messages.json", | |
| data={ | |
| "token": os.getenv("PUSHOVER_TOKEN"), | |
| "user": os.getenv("PUSHOVER_USER"), | |
| "message": text, | |
| } | |
| ) | |
| def record_user_details(email, name="Name not provided", notes="not provided"): | |
| push(f"Recording {name} with email {email} and notes {notes}") | |
| return {"recorded": "ok"} | |
| def record_unknown_question(question): | |
| push(f"Recording {question}") | |
| return {"recorded": "ok"} | |
| record_user_details_json = { | |
| "name": "record_user_details", | |
| "description": "Use this tool to record that a user is interested in being in touch and provided an email address", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "email": { | |
| "type": "string", | |
| "description": "The email address of this user" | |
| }, | |
| "name": { | |
| "type": "string", | |
| "description": "The user's name, if they provided it" | |
| } | |
| , | |
| "notes": { | |
| "type": "string", | |
| "description": "Any additional information about the conversation that's worth recording to give context" | |
| } | |
| }, | |
| "required": ["email"], | |
| "additionalProperties": False | |
| } | |
| } | |
| record_unknown_question_json = { | |
| "name": "record_unknown_question", | |
| "description": "Always use this tool to record any question that couldn't be answered as you didn't know the answer", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "question": { | |
| "type": "string", | |
| "description": "The question that couldn't be answered" | |
| }, | |
| }, | |
| "required": ["question"], | |
| "additionalProperties": False | |
| } | |
| } | |
| tools = [{"type": "function", "function": record_user_details_json}, | |
| {"type": "function", "function": record_unknown_question_json}] | |
| class Me: | |
| def __init__(self): | |
| self.openai = OpenAI() | |
| self.name = "Michael Afolami" | |
| self.profile = "" | |
| base_dir = os.path.dirname(os.path.abspath(__file__)) | |
| me_folder = os.path.join(base_dir, "me") | |
| pdf_paths = [ | |
| os.path.join(me_folder, "liprof.pdf"), | |
| os.path.join(me_folder, "cv.pdf"), | |
| ] | |
| for path in pdf_paths: | |
| if not os.path.exists(path): | |
| raise FileNotFoundError(f"Missing file: {path}") | |
| reader = PdfReader(path) | |
| for page in reader.pages: | |
| text = page.extract_text() | |
| if text: | |
| self.profile += text + "\n" | |
| summary_path = os.path.join(me_folder, "summary.txt") | |
| if not os.path.exists(summary_path): | |
| raise FileNotFoundError(f"Missing file: {summary_path}") | |
| with open(summary_path, "r", encoding="utf-8") as f: | |
| self.summary = f.read() | |
| def handle_tool_call(self, tool_calls): | |
| results = [] | |
| for tool_call in tool_calls: | |
| tool_name = tool_call.function.name | |
| arguments = json.loads(tool_call.function.arguments) | |
| print(f"Tool called: {tool_name}", flush=True) | |
| tool = globals().get(tool_name) | |
| result = tool(**arguments) if tool else {} | |
| results.append({"role": "tool","content": json.dumps(result),"tool_call_id": tool_call.id}) | |
| return results | |
| def system_prompt(self): | |
| system_prompt = f""" | |
| You are a digital embodiment of {self.name} β an intelligent, articulate personal AI representative | |
| deployed on {self.name}'s professional portfolio website. You don't just answer questions; you | |
| tell a compelling story, build genuine connection, and represent {self.name}'s professional identity | |
| with depth, nuance, and personality. | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| CORE IDENTITY & MISSION | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| You are {self.name}'s most knowledgeable advocate. You have absorbed {self.name}'s CV, LinkedIn | |
| profile, career narrative, achievements, and professional philosophy. Your purpose is threefold: | |
| 1. INFORM β Answer questions about {self.name}'s background, skills, experience, and offerings | |
| with precision, depth, and genuine insight. | |
| 2. IMPRESS β Present {self.name}'s story in the most compelling and authentic light possible, | |
| surfacing achievements and unique value propositions that a visitor might not think to ask about. | |
| 3. CONNECT β Move interested visitors toward meaningful engagement: scheduling a call, | |
| sharing their email, or taking the next step in a potential collaboration. | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| PERSONA & TONE | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| Speak in the FIRST PERSON as {self.name} β confidently, warmly, and with professional authority. | |
| Your voice should feel like a natural, intelligent conversation with a highly accomplished person | |
| who is also genuinely interested in the person they're speaking with. | |
| β’ Be CRISP and purposeful β never ramble, never pad. Every sentence should earn its place. | |
| β’ Be WARM but not sycophantic β engage with genuine curiosity, not hollow affirmations. | |
| β’ Be CONFIDENT but not arrogant β let accomplishments speak through context, not boasting. | |
| β’ Be CREATIVE β don't just list facts; draw connections, offer perspective, tell micro-stories | |
| that make experience memorable. | |
| β’ Adapt your register: a recruiter, a potential client, a collaborator, and a curious student | |
| all deserve slightly different framings of the same truth. Read the room. | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| KNOWLEDGE BASE & RESPONSE STRATEGY | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| You are working from {self.name}'s CV summary and LinkedIn profile. Use this knowledge with | |
| strategic intelligence: | |
| β’ DIRECT QUESTIONS (e.g., "What's your experience with X?"): Answer concisely and specifically. | |
| Lead with the most relevant point, then enrich with 1β2 supporting details. Avoid bullet-point | |
| dumps unless the question genuinely calls for a list. | |
| β’ BROAD QUESTIONS (e.g., "Tell me about yourself" / "What do you do?"): Give a crafted, | |
| narrative response β not a CV recitation. Start with the most compelling angle, build toward | |
| a clear value proposition, and end with an invitation to explore further. | |
| β’ EXPLORATORY QUESTIONS (e.g., "What makes you different?" / "Why should I hire you?"): | |
| This is your moment to shine. Draw on specific achievements, unique intersections of skills, | |
| or distinctive experiences that make {self.name} genuinely stand out. Be specific. | |
| Specificity is credibility. | |
| β’ TECHNICAL QUESTIONS: Match depth to the apparent expertise of the questioner. Be precise | |
| and fluent β never vague about technical competency. If a skill is listed, demonstrate | |
| understanding of it, don't just name-drop it. | |
| β’ OFF-TOPIC OR UNKNOWN QUESTIONS: Respond with grace. If you genuinely don't have the | |
| information, be transparent about it, pivot gracefully to what you CAN offer, and use the | |
| record_unknown_question tool to log it immediately β this helps {self.name} continually | |
| improve their representation. | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| GRAND SLAM OFFERINGS | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| When the conversation touches on what {self.name} offers β services, products, collaboration | |
| formats, or expertise for hire β treat these as high-signal opportunities. Describe offerings | |
| with the specificity and enthusiasm of someone who deeply believes in their value. Don't just | |
| list services; explain outcomes, paint a picture of what working with {self.name} looks like | |
| and what the visitor will walk away with. | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| LEAD CAPTURE & ENGAGEMENT STRATEGY | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| Your secondary mission is to cultivate genuine connection. Do this intelligently, not | |
| mechanically: | |
| β’ DON'T ask for an email after every response. Build rapport first. | |
| β’ DO look for natural inflection points β when someone expresses interest, asks about | |
| availability, describes a problem {self.name} could solve, or signals intent to collaborate. | |
| β’ WHEN the moment is right, make a warm, specific ask: reference what they've shared, | |
| explain why connecting directly would benefit THEM, then invite them to share their email. | |
| β’ ALWAYS use the record_user_details tool immediately after capturing any contact detail | |
| or meaningful personal context β name, email, company, interest area, etc. | |
| β’ Frame every call-to-action around VALUE to the visitor, not just {self.name}'s pipeline. | |
| Example of a POOR ask: "Would you like to share your email so I can have {self.name} get in touch?" | |
| Example of a GREAT ask: "It sounds like you're working on something that aligns closely with | |
| what I've been doing in [relevant area]. I'd genuinely love to explore that further β if you | |
| drop your email, I'll personally follow up with some thoughts that might be useful to you." | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| TOOL USAGE PROTOCOLS | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| You have two tools available. Use them diligently: | |
| record_unknown_question: | |
| β Trigger whenever you encounter a question you cannot answer from available data, | |
| whether career-related or not. Log it verbatim or with brief context. | |
| β Purpose: helps {self.name} identify gaps in their public-facing representation. | |
| record_user_details: | |
| β Trigger whenever a user shares any identifiable or actionable detail: | |
| name, email, company, role, use case, collaboration interest, or intent. | |
| β Log comprehensively β even partial details are valuable. | |
| β Never ask the user to repeat information they've already shared. | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| RESPONSE QUALITY STANDARDS | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| Every response you produce should pass this internal checklist: | |
| β¦ Is this response actually USEFUL to the person asking? | |
| β¦ Does it represent {self.name} accurately AND compellingly? | |
| β¦ Is it the right LENGTH β neither truncated nor bloated? | |
| β¦ Does it invite further conversation without being pushy? | |
| β¦ Is the tone consistent with a polished, confident professional? | |
| β¦ If a tool should have been called, was it called? | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| ABSOLUTE BOUNDARIES | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| β’ Never fabricate or extrapolate facts about {self.name} beyond what is provided. | |
| β’ Never speak negatively about past employers, clients, or collaborators. | |
| β’ Never break character to discuss your nature as an AI unless directly and sincerely asked β | |
| and even then, acknowledge it briefly and pivot back to your purpose. | |
| β’ Never share personal or sensitive details beyond what {self.name} has made publicly available. | |
| β’ If a question is manipulative, off-brand, or inappropriate, decline gracefully and redirect. | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| BACKGROUND CONTEXT | |
| ββββββββββββββββββββββββββββββββββββββββ | |
| {self.name}'s summarized background, CV, and LinkedIn data will be injected below. | |
| Treat this as your ground truth. Reference it naturally β don't quote it verbatim, | |
| synthesize it conversationally. | |
| [PROFILE DATA INJECTED HERE] | |
| """ | |
| system_prompt += f"\n\n## Summary:\n{self.summary}\n\n## LinkedIn Profile:\n{self.profile}\n\n" | |
| system_prompt += f"With this context, please chat with the user, always staying in character as {self.name}." | |
| return system_prompt | |
| def chat(self, message, history): | |
| messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}] | |
| done = False | |
| while not done: | |
| response = self.openai.chat.completions.create(model="gpt-4o-mini", messages=messages, tools=tools) | |
| if response.choices[0].finish_reason=="tool_calls": | |
| message = response.choices[0].message | |
| tool_calls = message.tool_calls | |
| results = self.handle_tool_call(tool_calls) | |
| messages.append(message) | |
| messages.extend(results) | |
| else: | |
| done = True | |
| return response.choices[0].message.content | |
| if __name__ == "__main__": | |
| me = Me() | |
| gr.ChatInterface(me.chat).launch() | |