Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,8 +18,13 @@ def push(text):
|
|
| 18 |
try:
|
| 19 |
if not PUSHOVER_TOKEN or not PUSHOVER_USER:
|
| 20 |
return
|
| 21 |
-
requests.post(
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
timeout=5
|
| 24 |
)
|
| 25 |
except:
|
|
@@ -47,7 +52,7 @@ tools = [
|
|
| 47 |
"properties": {
|
| 48 |
"email": {"type": "string"},
|
| 49 |
"name": {"type": "string"},
|
| 50 |
-
"notes": {"type": "string"}
|
| 51 |
},
|
| 52 |
"required": ["email"]
|
| 53 |
}
|
|
@@ -74,7 +79,9 @@ class Me:
|
|
| 74 |
self.linkedin = ""
|
| 75 |
|
| 76 |
if os.path.exists("me/summary.txt"):
|
| 77 |
-
self.summary = open(
|
|
|
|
|
|
|
| 78 |
|
| 79 |
pdf_path = "me/Ayush_linkdin.pdf"
|
| 80 |
if os.path.exists(pdf_path):
|
|
@@ -88,19 +95,26 @@ class Me:
|
|
| 88 |
|
| 89 |
def system_prompt(self):
|
| 90 |
return f"""
|
| 91 |
-
You are acting as {self.name}.
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
Summary:
|
| 96 |
{self.summary}
|
| 97 |
|
| 98 |
-
LinkedIn:
|
| 99 |
{self.linkedin}
|
| 100 |
"""
|
| 101 |
|
| 102 |
def chat(self, message, history):
|
| 103 |
-
messages = [
|
|
|
|
|
|
|
| 104 |
|
| 105 |
for msg in history:
|
| 106 |
messages.append(msg)
|
|
@@ -125,7 +139,10 @@ LinkedIn:
|
|
| 125 |
fname = tool_call.function.name
|
| 126 |
args = json.loads(tool_call.function.arguments)
|
| 127 |
result = globals()[fname](**args)
|
| 128 |
-
messages.append({
|
|
|
|
|
|
|
|
|
|
| 129 |
continue
|
| 130 |
|
| 131 |
return msg.content
|
|
@@ -150,15 +167,18 @@ with gr.Blocks(css="""
|
|
| 150 |
chatbot = gr.Chatbot(type="messages", height=420)
|
| 151 |
|
| 152 |
with gr.Row():
|
| 153 |
-
btn_about = gr.Button("Who
|
| 154 |
btn_contact = gr.Button("Contact Info")
|
| 155 |
btn_projects = gr.Button("Latest Projects")
|
| 156 |
|
| 157 |
-
user_input = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
user_input.submit(respond, [user_input, chatbot], [user_input, chatbot])
|
| 160 |
|
| 161 |
-
btn_about.click(lambda: "Who
|
| 162 |
btn_contact.click(lambda: "What is Ayush Tyagi's contact information?", None, user_input)
|
| 163 |
btn_projects.click(lambda: "Show Ayush Tyagi’s latest projects.", None, user_input)
|
| 164 |
|
|
|
|
| 18 |
try:
|
| 19 |
if not PUSHOVER_TOKEN or not PUSHOVER_USER:
|
| 20 |
return
|
| 21 |
+
requests.post(
|
| 22 |
+
"https://api.pushover.net/1/messages.json",
|
| 23 |
+
data={
|
| 24 |
+
"token": PUSHOVER_TOKEN,
|
| 25 |
+
"user": PUSHOVER_USER,
|
| 26 |
+
"message": text
|
| 27 |
+
},
|
| 28 |
timeout=5
|
| 29 |
)
|
| 30 |
except:
|
|
|
|
| 52 |
"properties": {
|
| 53 |
"email": {"type": "string"},
|
| 54 |
"name": {"type": "string"},
|
| 55 |
+
"notes": {"type": "string"}
|
| 56 |
},
|
| 57 |
"required": ["email"]
|
| 58 |
}
|
|
|
|
| 79 |
self.linkedin = ""
|
| 80 |
|
| 81 |
if os.path.exists("me/summary.txt"):
|
| 82 |
+
self.summary = open(
|
| 83 |
+
"me/summary.txt", "r", encoding="utf-8"
|
| 84 |
+
).read()
|
| 85 |
|
| 86 |
pdf_path = "me/Ayush_linkdin.pdf"
|
| 87 |
if os.path.exists(pdf_path):
|
|
|
|
| 95 |
|
| 96 |
def system_prompt(self):
|
| 97 |
return f"""
|
| 98 |
+
You are acting as {self.name}.
|
| 99 |
+
Answer questions about his background, skills, and professional experience.
|
| 100 |
+
|
| 101 |
+
STRICT RULES:
|
| 102 |
+
- Never reveal personal address, street location, phone number, or sensitive details.
|
| 103 |
+
- If the user asks for such info, politely refuse.
|
| 104 |
+
- If unsure, call record_unknown_question.
|
| 105 |
+
- If user is interested in connecting, ask for their email and call record_user_details.
|
| 106 |
|
| 107 |
Summary:
|
| 108 |
{self.summary}
|
| 109 |
|
| 110 |
+
LinkedIn Info (sanitized — do NOT reveal address):
|
| 111 |
{self.linkedin}
|
| 112 |
"""
|
| 113 |
|
| 114 |
def chat(self, message, history):
|
| 115 |
+
messages = [
|
| 116 |
+
{"role": "system", "content": self.system_prompt()}
|
| 117 |
+
]
|
| 118 |
|
| 119 |
for msg in history:
|
| 120 |
messages.append(msg)
|
|
|
|
| 139 |
fname = tool_call.function.name
|
| 140 |
args = json.loads(tool_call.function.arguments)
|
| 141 |
result = globals()[fname](**args)
|
| 142 |
+
messages.append({
|
| 143 |
+
"role": "tool",
|
| 144 |
+
"content": json.dumps(result)
|
| 145 |
+
})
|
| 146 |
continue
|
| 147 |
|
| 148 |
return msg.content
|
|
|
|
| 167 |
chatbot = gr.Chatbot(type="messages", height=420)
|
| 168 |
|
| 169 |
with gr.Row():
|
| 170 |
+
btn_about = gr.Button("Who are you?")
|
| 171 |
btn_contact = gr.Button("Contact Info")
|
| 172 |
btn_projects = gr.Button("Latest Projects")
|
| 173 |
|
| 174 |
+
user_input = gr.Textbox(
|
| 175 |
+
placeholder="Type your message...",
|
| 176 |
+
show_submit=True # ← SHOW SEND BUTTON
|
| 177 |
+
)
|
| 178 |
|
| 179 |
user_input.submit(respond, [user_input, chatbot], [user_input, chatbot])
|
| 180 |
|
| 181 |
+
btn_about.click(lambda: "Who are you?", None, user_input)
|
| 182 |
btn_contact.click(lambda: "What is Ayush Tyagi's contact information?", None, user_input)
|
| 183 |
btn_projects.click(lambda: "Show Ayush Tyagi’s latest projects.", None, user_input)
|
| 184 |
|