freddaoism commited on
Commit
768d098
·
verified ·
1 Parent(s): 976bdac

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-39.pyc +0 -0
  2. app.py +69 -24
__pycache__/app.cpython-39.pyc ADDED
Binary file (5.95 kB). View file
 
app.py CHANGED
@@ -10,14 +10,27 @@ import gradio as gr
10
  load_dotenv(override=True)
11
 
12
  def push(text):
13
- requests.post(
14
- "https://api.pushover.net/1/messages.json",
15
- data={
16
- "token": os.getenv("PUSHOVER_TOKEN"),
17
- "user": os.getenv("PUSHOVER_USER"),
18
- "message": text,
19
- }
20
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23
  def record_user_details(email, name="Name not provided", notes="not provided"):
@@ -77,26 +90,58 @@ class Me:
77
 
78
  def __init__(self):
79
  self.openai = OpenAI()
80
- self.name = "Ed Donner"
81
- reader = PdfReader("me/linkedin.pdf")
82
- self.linkedin = ""
83
- for page in reader.pages:
84
- text = page.extract_text()
85
- if text:
86
- self.linkedin += text
87
- with open("me/summary.txt", "r", encoding="utf-8") as f:
88
- self.summary = f.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
 
91
  def handle_tool_call(self, tool_calls):
92
  results = []
93
  for tool_call in tool_calls:
94
- tool_name = tool_call.function.name
95
- arguments = json.loads(tool_call.function.arguments)
96
- print(f"Tool called: {tool_name}", flush=True)
97
- tool = globals().get(tool_name)
98
- result = tool(**arguments) if tool else {}
99
- results.append({"role": "tool","content": json.dumps(result),"tool_call_id": tool_call.id})
 
 
 
 
 
 
 
 
 
 
 
100
  return results
101
 
102
  def system_prompt(self):
@@ -130,5 +175,5 @@ If the user is engaging in discussion, try to steer them towards getting in touc
130
 
131
  if __name__ == "__main__":
132
  me = Me()
133
- gr.ChatInterface(me.chat, type="messages").launch()
134
 
 
10
  load_dotenv(override=True)
11
 
12
  def push(text):
13
+ token = os.getenv("PUSHOVER_TOKEN")
14
+ user = os.getenv("PUSHOVER_USER")
15
+ if not token or not user:
16
+ print("Pushover: Missing PUSHOVER_TOKEN or PUSHOVER_USER", flush=True)
17
+ return
18
+ try:
19
+ response = requests.post(
20
+ "https://api.pushover.net/1/messages.json",
21
+ data={
22
+ "token": token,
23
+ "user": user,
24
+ "message": text,
25
+ },
26
+ timeout=10
27
+ )
28
+ response.raise_for_status()
29
+ print(f"Pushover: Message sent successfully", flush=True)
30
+ except requests.exceptions.RequestException as e:
31
+ print(f"Pushover: Error sending message - {e}", flush=True)
32
+ except Exception as e:
33
+ print(f"Pushover: Unexpected error - {e}", flush=True)
34
 
35
 
36
  def record_user_details(email, name="Name not provided", notes="not provided"):
 
90
 
91
  def __init__(self):
92
  self.openai = OpenAI()
93
+ self.name = "Fred Dao"
94
+
95
+ # Get the directory where this script is located
96
+ script_dir = os.path.dirname(os.path.abspath(__file__))
97
+ linkedin_path = os.path.join(script_dir, "me", "linkedin.pdf")
98
+ summary_path = os.path.join(script_dir, "me", "summary.txt")
99
+
100
+ try:
101
+ reader = PdfReader(linkedin_path)
102
+ self.linkedin = ""
103
+ for page in reader.pages:
104
+ text = page.extract_text()
105
+ if text:
106
+ self.linkedin += text
107
+ except FileNotFoundError:
108
+ print(f"Warning: Could not find {linkedin_path}", flush=True)
109
+ self.linkedin = ""
110
+ except Exception as e:
111
+ print(f"Error reading LinkedIn PDF: {e}", flush=True)
112
+ self.linkedin = ""
113
+
114
+ try:
115
+ with open(summary_path, "r", encoding="utf-8") as f:
116
+ self.summary = f.read()
117
+ except FileNotFoundError:
118
+ print(f"Warning: Could not find {summary_path}", flush=True)
119
+ self.summary = ""
120
+ except Exception as e:
121
+ print(f"Error reading summary file: {e}", flush=True)
122
+ self.summary = ""
123
 
124
 
125
  def handle_tool_call(self, tool_calls):
126
  results = []
127
  for tool_call in tool_calls:
128
+ try:
129
+ tool_name = tool_call.function.name
130
+ arguments = json.loads(tool_call.function.arguments)
131
+ print(f"Tool called: {tool_name}", flush=True)
132
+ tool = globals().get(tool_name)
133
+ if tool:
134
+ result = tool(**arguments)
135
+ else:
136
+ print(f"Warning: Tool '{tool_name}' not found", flush=True)
137
+ result = {"error": "Tool not found"}
138
+ results.append({"role": "tool", "content": json.dumps(result), "tool_call_id": tool_call.id})
139
+ except json.JSONDecodeError as e:
140
+ print(f"Error parsing tool arguments: {e}", flush=True)
141
+ results.append({"role": "tool", "content": json.dumps({"error": "Invalid arguments"}), "tool_call_id": tool_call.id})
142
+ except Exception as e:
143
+ print(f"Error executing tool: {e}", flush=True)
144
+ results.append({"role": "tool", "content": json.dumps({"error": str(e)}), "tool_call_id": tool_call.id})
145
  return results
146
 
147
  def system_prompt(self):
 
175
 
176
  if __name__ == "__main__":
177
  me = Me()
178
+ gr.ChatInterface(me.chat, type="messages").launch(share=True)
179