Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,8 +18,7 @@ def push(text):
|
|
| 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={"token": PUSHOVER_TOKEN, "user": PUSHOVER_USER, "message": text},
|
| 24 |
timeout=5
|
| 25 |
)
|
|
@@ -48,7 +47,7 @@ tools = [
|
|
| 48 |
"properties": {
|
| 49 |
"email": {"type": "string"},
|
| 50 |
"name": {"type": "string"},
|
| 51 |
-
"notes": {"type": "string"}
|
| 52 |
},
|
| 53 |
"required": ["email"]
|
| 54 |
}
|
|
@@ -89,9 +88,9 @@ class Me:
|
|
| 89 |
|
| 90 |
def system_prompt(self):
|
| 91 |
return f"""
|
| 92 |
-
You are acting as {self.name}.
|
| 93 |
-
If unsure,
|
| 94 |
-
If user is interested, ask for
|
| 95 |
|
| 96 |
Summary:
|
| 97 |
{self.summary}
|
|
@@ -103,8 +102,8 @@ LinkedIn:
|
|
| 103 |
def chat(self, message, history):
|
| 104 |
messages = [{"role": "system", "content": self.system_prompt()}]
|
| 105 |
|
| 106 |
-
for
|
| 107 |
-
messages.append(
|
| 108 |
|
| 109 |
messages.append({"role": "user", "content": message})
|
| 110 |
|
|
@@ -114,7 +113,7 @@ LinkedIn:
|
|
| 114 |
messages=messages,
|
| 115 |
tools=tools,
|
| 116 |
tool_choice="auto",
|
| 117 |
-
max_tokens=
|
| 118 |
)
|
| 119 |
|
| 120 |
choice = response.choices[0]
|
|
@@ -122,9 +121,9 @@ LinkedIn:
|
|
| 122 |
finish = choice.finish_reason
|
| 123 |
|
| 124 |
if finish == "tool_calls":
|
| 125 |
-
for
|
| 126 |
-
fname =
|
| 127 |
-
args = json.loads(
|
| 128 |
result = globals()[fname](**args)
|
| 129 |
messages.append({"role": "tool", "content": json.dumps(result)})
|
| 130 |
continue
|
|
@@ -136,37 +135,38 @@ me = Me()
|
|
| 136 |
|
| 137 |
def respond(user_message, history):
|
| 138 |
bot_reply = me.chat(user_message, history)
|
| 139 |
-
history.append(
|
| 140 |
-
history.append(
|
| 141 |
return "", history
|
| 142 |
|
| 143 |
|
| 144 |
with gr.Blocks(css="""
|
| 145 |
body, .gradio-container { background-color: #0d0d0d; color: white; }
|
| 146 |
-
.gr-button { background-color: #ff4da6 !important;
|
|
|
|
| 147 |
.gr-button:hover { background-color: #ff1a8c !important; }
|
| 148 |
""") as ui:
|
| 149 |
|
| 150 |
-
gr.
|
| 151 |
|
| 152 |
with gr.Row():
|
| 153 |
-
btn_contact = gr.Button("Contact Info")
|
| 154 |
btn_about = gr.Button("Who is Ayush?")
|
|
|
|
| 155 |
btn_projects = gr.Button("Latest Projects")
|
| 156 |
|
| 157 |
-
chatbot = gr.Chatbot(height=450)
|
| 158 |
user_input = gr.Textbox(placeholder="Type your message...")
|
| 159 |
|
| 160 |
user_input.submit(respond, [user_input, chatbot], [user_input, chatbot])
|
| 161 |
|
| 162 |
-
btn_contact.click(lambda: "What is Ayush Tyagi's contact information?", None, user_input)
|
| 163 |
-
btn_contact.click(respond, [user_input, chatbot], [user_input, chatbot])
|
| 164 |
-
|
| 165 |
btn_about.click(lambda: "Who is Ayush Tyagi?", None, user_input)
|
| 166 |
btn_about.click(respond, [user_input, chatbot], [user_input, chatbot])
|
| 167 |
|
|
|
|
|
|
|
|
|
|
| 168 |
btn_projects.click(lambda: "Show Ayush Tyagi’s latest projects.", None, user_input)
|
| 169 |
btn_projects.click(respond, [user_input, chatbot], [user_input, chatbot])
|
| 170 |
|
|
|
|
| 171 |
if __name__ == "__main__":
|
| 172 |
ui.launch()
|
|
|
|
| 18 |
try:
|
| 19 |
if not PUSHOVER_TOKEN or not PUSHOVER_USER:
|
| 20 |
return
|
| 21 |
+
requests.post("https://api.pushover.net/1/messages.json",
|
|
|
|
| 22 |
data={"token": PUSHOVER_TOKEN, "user": PUSHOVER_USER, "message": text},
|
| 23 |
timeout=5
|
| 24 |
)
|
|
|
|
| 47 |
"properties": {
|
| 48 |
"email": {"type": "string"},
|
| 49 |
"name": {"type": "string"},
|
| 50 |
+
"notes": {"type": "string"},
|
| 51 |
},
|
| 52 |
"required": ["email"]
|
| 53 |
}
|
|
|
|
| 88 |
|
| 89 |
def system_prompt(self):
|
| 90 |
return f"""
|
| 91 |
+
You are acting as {self.name}. Answer questions about his background, skills and experience.
|
| 92 |
+
If unsure, call record_unknown_question.
|
| 93 |
+
If user is interested, ask for email and call record_user_details.
|
| 94 |
|
| 95 |
Summary:
|
| 96 |
{self.summary}
|
|
|
|
| 102 |
def chat(self, message, history):
|
| 103 |
messages = [{"role": "system", "content": self.system_prompt()}]
|
| 104 |
|
| 105 |
+
for msg in history:
|
| 106 |
+
messages.append(msg)
|
| 107 |
|
| 108 |
messages.append({"role": "user", "content": message})
|
| 109 |
|
|
|
|
| 113 |
messages=messages,
|
| 114 |
tools=tools,
|
| 115 |
tool_choice="auto",
|
| 116 |
+
max_tokens=500
|
| 117 |
)
|
| 118 |
|
| 119 |
choice = response.choices[0]
|
|
|
|
| 121 |
finish = choice.finish_reason
|
| 122 |
|
| 123 |
if finish == "tool_calls":
|
| 124 |
+
for tool_call in msg.tool_calls:
|
| 125 |
+
fname = tool_call.function.name
|
| 126 |
+
args = json.loads(tool_call.function.arguments)
|
| 127 |
result = globals()[fname](**args)
|
| 128 |
messages.append({"role": "tool", "content": json.dumps(result)})
|
| 129 |
continue
|
|
|
|
| 135 |
|
| 136 |
def respond(user_message, history):
|
| 137 |
bot_reply = me.chat(user_message, history)
|
| 138 |
+
history.append({"role": "user", "content": user_message})
|
| 139 |
+
history.append({"role": "assistant", "content": bot_reply})
|
| 140 |
return "", history
|
| 141 |
|
| 142 |
|
| 143 |
with gr.Blocks(css="""
|
| 144 |
body, .gradio-container { background-color: #0d0d0d; color: white; }
|
| 145 |
+
.gr-button { background-color: #ff4da6 !important;
|
| 146 |
+
color: black !important; font-weight: 600 !important; }
|
| 147 |
.gr-button:hover { background-color: #ff1a8c !important; }
|
| 148 |
""") as ui:
|
| 149 |
|
| 150 |
+
chatbot = gr.Chatbot(type="messages", height=420)
|
| 151 |
|
| 152 |
with gr.Row():
|
|
|
|
| 153 |
btn_about = gr.Button("Who is Ayush?")
|
| 154 |
+
btn_contact = gr.Button("Contact Info")
|
| 155 |
btn_projects = gr.Button("Latest Projects")
|
| 156 |
|
|
|
|
| 157 |
user_input = gr.Textbox(placeholder="Type your message...")
|
| 158 |
|
| 159 |
user_input.submit(respond, [user_input, chatbot], [user_input, chatbot])
|
| 160 |
|
|
|
|
|
|
|
|
|
|
| 161 |
btn_about.click(lambda: "Who is Ayush Tyagi?", None, user_input)
|
| 162 |
btn_about.click(respond, [user_input, chatbot], [user_input, chatbot])
|
| 163 |
|
| 164 |
+
btn_contact.click(lambda: "What is Ayush Tyagi's contact information?", None, user_input)
|
| 165 |
+
btn_contact.click(respond, [user_input, chatbot], [user_input, chatbot])
|
| 166 |
+
|
| 167 |
btn_projects.click(lambda: "Show Ayush Tyagi’s latest projects.", None, user_input)
|
| 168 |
btn_projects.click(respond, [user_input, chatbot], [user_input, chatbot])
|
| 169 |
|
| 170 |
+
|
| 171 |
if __name__ == "__main__":
|
| 172 |
ui.launch()
|