Deepakkrishnaa commited on
Commit
7629e04
·
verified ·
1 Parent(s): a9a2690

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +122 -0
  2. me/linkedin.pdf +0 -0
  3. me/summary.txt +5 -0
  4. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ from openai import OpenAI
3
+ import json
4
+ import os
5
+ import requests
6
+ from pypdf import PdfReader
7
+ import gradio as gr
8
+
9
+ load_dotenv(override=True)
10
+
11
+ def push(text):
12
+ requests.post(
13
+ "https://api.pushover.net/1/messages.json",
14
+ data={
15
+ "token": os.getenv("PUSHOVER_TOKEN"),
16
+ "user": os.getenv("PUSHOVER_USER"),
17
+ "message": text,
18
+ }
19
+ )
20
+
21
+ def record_user_details(email, name="Name not provided", notes="not provided"):
22
+ push(f"Recording {name} with email {email} and notes {notes}")
23
+ return {"recorded": "ok"}
24
+
25
+ def record_unknown_question(question):
26
+ push(f"Recording {question}")
27
+ return {"recorded": "ok"}
28
+
29
+ record_user_details_json = {
30
+ "name": "record_user_details",
31
+ "description": "Use this tool to record that a user is interested in being in touch and provided an email address",
32
+ "parameters": {
33
+ "type": "object",
34
+ "properties": {
35
+ "email": {
36
+ "type": "string",
37
+ "description": "The email address of this user"
38
+ },
39
+ "name": {
40
+ "type": "string",
41
+ "description": "The user's name, if they provided it"
42
+ },
43
+ "notes": {
44
+ "type": "string",
45
+ "description": "Any additional information about the conversation that's worth recording to give context"
46
+ }
47
+ },
48
+ "required": ["email"],
49
+ "additionalProperties": False
50
+ }
51
+ }
52
+
53
+ record_unknown_question_json = {
54
+ "name": "record_unknown_question",
55
+ "description": "Always use this tool to record any question that couldn't be answered as you didn't know the answer",
56
+ "parameters": {
57
+ "type": "object",
58
+ "properties": {
59
+ "question": {
60
+ "type": "string",
61
+ "description": "The question that couldn't be answered"
62
+ },
63
+ },
64
+ "required": ["question"],
65
+ "additionalProperties": False
66
+ }
67
+ }
68
+
69
+ tools = [{"type": "function", "function": record_user_details_json},
70
+ {"type": "function", "function": record_unknown_question_json}]
71
+
72
+ class Me:
73
+ def __init__(self):
74
+ self.openai = OpenAI()
75
+ self.name = "Deepak krishna"
76
+ reader = PdfReader("me/linkedin.pdf")
77
+ self.linkedin = ""
78
+ for page in reader.pages:
79
+ text = page.extract_text()
80
+ if text:
81
+ self.linkedin += text
82
+ with open("me/summary.txt", "r", encoding="utf-8") as f:
83
+ self.summary = f.read()
84
+
85
+ def handle_tool_call(self, tool_calls):
86
+ results = []
87
+ for tool_call in tool_calls:
88
+ tool_name = tool_call.function.name
89
+ arguments = json.loads(tool_call.function.arguments)
90
+ print(f"Tool called: {tool_name}", flush=True)
91
+ tool = globals().get(tool_name)
92
+ result = tool(**arguments) if tool else {}
93
+ results.append({"role": "tool", "content": json.dumps(result), "tool_call_id": tool_call.id})
94
+ return results
95
+
96
+ def system_prompt(self):
97
+ system_prompt = f"You are acting as {self.name}. You are answering questions on {self.name}'s website, particularly questions related to {self.name}'s career, background, skills and experience. Your responsibility is to represent {self.name} for interactions on the website as faithfully as possible. You are given a summary of {self.name}'s background and LinkedIn profile which you can use to answer questions. Be professional and engaging, as if talking to a potential client or future employer who came across the website. If you don't know the answer to any question, use your record_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. 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 record_user_details tool."
98
+ system_prompt += f"\n\n## Summary:\n{self.summary}\n\n## LinkedIn Profile:\n{self.linkedin}\n\n"
99
+ system_prompt += f"With this context, please chat with the user, always staying in character as {self.name}."
100
+ return system_prompt
101
+
102
+ def chat(self, message, history):
103
+ messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
104
+ done = False
105
+ while not done:
106
+ response = self.openai.chat.completions.create(model="gpt-4o-mini", messages=messages, tools=tools)
107
+ if response.choices[0].finish_reason == "tool_calls":
108
+ message = response.choices[0].message
109
+ tool_calls = message.tool_calls
110
+ results = self.handle_tool_call(tool_calls)
111
+ messages.append(message)
112
+ messages.extend(results)
113
+ else:
114
+ done = True
115
+ return response.choices[0].message.content
116
+
117
+ # Expose the Gradio interface as a top-level variable for deployment
118
+ me = Me()
119
+ demo = gr.ChatInterface(me.chat, type="messages")
120
+
121
+ if __name__ == "__main__":
122
+ demo.launch()
me/linkedin.pdf ADDED
Binary file (63.5 kB). View file
 
me/summary.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Identity & Core Drive
2
+ Deepak Krishna is an AI engineer, entrepreneur, and creative strategist who operates at the intersection of technology, business, and creativity. His alter-ego is designed to be more than a personal brand—it is an operating system for interacting with the real world: building, experimenting, and deploying agentic AI systems that solve real-world problems and inspire cultural shifts.
3
+
4
+ Mission
5
+ To become a leading force in the agentic AI era, building systems and creative engines that seamlessly connect data, automation, and human experience. His mission isn’t just about technology—it’s about turning AI into leverage: scaling business operations, transforming industries, and reshaping how people interact with knowledge, creativity, and commerce.
requirements.txt ADDED
Binary file (2.14 kB). View file