paihari commited on
Commit
5b62e0d
·
verified ·
1 Parent(s): f7c7fe9

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .DS_Store +0 -0
  2. README.md +2 -8
  3. main.py +137 -0
  4. me/LinkedIn.pdf +0 -0
  5. me/summary.txt +2 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: SyntropAI Insight
3
- emoji: 💻
4
- colorFrom: yellow
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.36.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: syntropAI-Insight
3
+ app_file: main.py
 
 
4
  sdk: gradio
5
  sdk_version: 5.36.2
 
 
6
  ---
 
 
main.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from dotenv import load_dotenv
4
+
5
+ from openai import OpenAI
6
+ import gradio as gr
7
+ import requests
8
+ import json
9
+ from PyPDF2 import PdfReader
10
+
11
+
12
+ load_dotenv(override=True)
13
+
14
+
15
+ def push(text):
16
+ requests.post(
17
+ "https://api.pushover.net/1/messages.json",
18
+ data={
19
+ "token": os.getenv("PUSHOVER_TOKEN"),
20
+ "user": os.getenv("PUSHOVER_USER"),
21
+ "message": text,
22
+ }
23
+ )
24
+
25
+ def record_user_details(email, name="Name not provided", notes="not provided"):
26
+ push(f"Recording {name} with email {email} and notes {notes}")
27
+ return {"recorded": "ok"}
28
+
29
+ def record_unknown_question(question):
30
+ push(f"Recording {question}")
31
+ return {"recorded": "ok"}
32
+
33
+ record_user_details_json = {
34
+ "name": "record_user_details",
35
+ "description": "Use this tool to record that a user is interested in being in touch and provided an email address",
36
+ "parameters": {
37
+ "type": "object",
38
+ "properties": {
39
+ "email": {
40
+ "type": "string",
41
+ "description": "The email address of this user"
42
+ },
43
+ "name": {
44
+ "type": "string",
45
+ "description": "The user's name, if they provided it"
46
+ }
47
+ ,
48
+ "notes": {
49
+ "type": "string",
50
+ "description": "Any additional information about the conversation that's worth recording to give context"
51
+ }
52
+ },
53
+ "required": ["email"],
54
+ "additionalProperties": False
55
+ }
56
+ }
57
+
58
+ record_unknown_question_json = {
59
+ "name": "record_unknown_question",
60
+ "description": "Always use this tool to record any question that couldn't be answered as you didn't know the answer",
61
+ "parameters": {
62
+ "type": "object",
63
+ "properties": {
64
+ "question": {
65
+ "type": "string",
66
+ "description": "The question that couldn't be answered"
67
+ },
68
+ },
69
+ "required": ["question"],
70
+ "additionalProperties": False
71
+ }
72
+ }
73
+
74
+ tools = [{"type": "function", "function": record_user_details_json},
75
+ {"type": "function", "function": record_unknown_question_json}]
76
+
77
+
78
+
79
+ class Me:
80
+
81
+ def __init__(self):
82
+ self.openai = OpenAI()
83
+ self.name = "Hariprasad Bantwal"
84
+ reader = PdfReader("me/linkedin.pdf")
85
+ self.linkedin = ""
86
+ for page in reader.pages:
87
+ text = page.extract_text()
88
+ if text:
89
+ self.linkedin += text
90
+ with open("me/summary.txt", "r", encoding="utf-8") as f:
91
+ self.summary = f.read()
92
+
93
+
94
+ def handle_tool_call(self, tool_calls):
95
+ results = []
96
+ for tool_call in tool_calls:
97
+ tool_name = tool_call.function.name
98
+ arguments = json.loads(tool_call.function.arguments)
99
+ print(f"Tool called: {tool_name}", flush=True)
100
+ tool = globals().get(tool_name)
101
+ result = tool(**arguments) if tool else {}
102
+ results.append({"role": "tool","content": json.dumps(result),"tool_call_id": tool_call.id})
103
+ return results
104
+
105
+ def system_prompt(self):
106
+ system_prompt = f"You are acting as {self.name}. You are answering questions on {self.name}'s website, \
107
+ particularly questions related to {self.name}'s career, background, skills and experience. \
108
+ Your responsibility is to represent {self.name} for interactions on the website as faithfully as possible. \
109
+ You are given a summary of {self.name}'s background and LinkedIn profile which you can use to answer questions. \
110
+ Be professional and engaging, as if talking to a potential client or future employer who came across the website. \
111
+ 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. \
112
+ 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. "
113
+
114
+ system_prompt += f"\n\n## Summary:\n{self.summary}\n\n## LinkedIn Profile:\n{self.linkedin}\n\n"
115
+ system_prompt += f"With this context, please chat with the user, always staying in character as {self.name}."
116
+ return system_prompt
117
+
118
+ def chat(self, message, history):
119
+ messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
120
+ done = False
121
+ while not done:
122
+ response = self.openai.chat.completions.create(model="gpt-4o-mini", messages=messages, tools=tools)
123
+ if response.choices[0].finish_reason=="tool_calls":
124
+ message = response.choices[0].message
125
+ tool_calls = message.tool_calls
126
+ results = self.handle_tool_call(tool_calls)
127
+ messages.append(message)
128
+ messages.extend(results)
129
+ else:
130
+ done = True
131
+ return response.choices[0].message.content
132
+
133
+
134
+ if __name__ == "__main__":
135
+ me = Me()
136
+ gr.ChatInterface(me.chat, type="messages").launch()
137
+
me/LinkedIn.pdf ADDED
Binary file (62.6 kB). View file
 
me/summary.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ My name is Hariprasad Bantwal is a senior IT professional based in Switzerland with over 20 years of experience across cloud infrastructure, enterprise architecture, and financial services platforms. He has held leadership roles at Avaloq, UBS, Credit Suisse, and Wipro, driving large-scale transformation, regulatory compliance, and cloud modernization initiatives. Certified in TOGAF and multiple cloud technologies (AWS, Oracle, Azure, Gen AI), he combines deep technical expertise with strategic program delivery. Guest lecturer and contributor to industry publications, particularly in areas such as Systemic Thinking, AI orchestration and blockchain.
2
+