Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
|
|
8 |
import gdown
|
9 |
from datetime import datetime
|
10 |
from pathlib import Path
|
|
|
11 |
|
12 |
load_dotenv(override=True)
|
13 |
|
@@ -38,9 +39,9 @@ record_user_details_json = {
|
|
38 |
"parameters": {
|
39 |
"type": "object",
|
40 |
"properties": {
|
41 |
-
"email": {"type": "string"
|
42 |
-
"name": {"type": "string"
|
43 |
-
"notes": {"type": "string"
|
44 |
},
|
45 |
"required": ["email"],
|
46 |
"additionalProperties": False
|
@@ -49,11 +50,11 @@ record_user_details_json = {
|
|
49 |
|
50 |
record_unknown_question_json = {
|
51 |
"name": "record_unknown_question",
|
52 |
-
"description": "Record
|
53 |
"parameters": {
|
54 |
"type": "object",
|
55 |
"properties": {
|
56 |
-
"question": {"type": "string"
|
57 |
},
|
58 |
"required": ["question"],
|
59 |
"additionalProperties": False
|
@@ -73,17 +74,17 @@ class Me:
|
|
73 |
Path("chat_logs").mkdir(exist_ok=True)
|
74 |
|
75 |
# Download LinkedIn PDF
|
76 |
-
|
77 |
-
gdown.download(f"https://drive.google.com/uc?id={linkedin_id}", "linkedin.pdf", quiet=False)
|
78 |
reader = PdfReader("linkedin.pdf")
|
79 |
self.linkedin = "".join(page.extract_text() or "" for page in reader.pages)
|
80 |
|
81 |
# Download summary.txt
|
82 |
-
|
83 |
-
gdown.download(f"https://drive.google.com/uc?id={summary_id}", "summary.txt", quiet=False)
|
84 |
with open("summary.txt", "r", encoding="utf-8") as f:
|
85 |
self.summary = f.read()
|
86 |
|
|
|
|
|
87 |
def system_prompt(self):
|
88 |
return f"""You are acting as {self.name}. You're answering questions on {self.name}'s website about his career, experience, and skills.
|
89 |
Be professional and conversational, as if talking to a potential employer or client.
|
@@ -130,6 +131,9 @@ If you can't answer something, call `record_unknown_question`. If a user seems i
|
|
130 |
full_response += delta.content
|
131 |
yield full_response
|
132 |
|
|
|
|
|
|
|
133 |
self.session_log.append({"role": "assistant", "content": full_response})
|
134 |
self.save_session_log()
|
135 |
|
@@ -139,18 +143,27 @@ If you can't answer something, call `record_unknown_question`. If a user seems i
|
|
139 |
with open(filename, "w", encoding="utf-8") as f:
|
140 |
json.dump(self.session_log, f, indent=2)
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
me = Me()
|
143 |
|
|
|
144 |
with gr.Blocks(title="Jacob Isaacson Chatbot") as iface:
|
145 |
with gr.Row():
|
146 |
-
gr.Image("jacob.png", width=
|
147 |
-
gr.Markdown("### Chat with Jacob Isaacson\nAsk about Jacob's background, skills, or
|
148 |
|
149 |
gr.ChatInterface(
|
150 |
fn=me.chat_stream,
|
151 |
chatbot=gr.Chatbot(show_copy_button=True),
|
152 |
examples=["What is Jacob's experience with AI?", "Tell me about his recent projects."],
|
153 |
-
type="messages"
|
154 |
)
|
155 |
|
156 |
if __name__ == "__main__":
|
|
|
8 |
import gdown
|
9 |
from datetime import datetime
|
10 |
from pathlib import Path
|
11 |
+
import zipfile
|
12 |
|
13 |
load_dotenv(override=True)
|
14 |
|
|
|
39 |
"parameters": {
|
40 |
"type": "object",
|
41 |
"properties": {
|
42 |
+
"email": {"type": "string"},
|
43 |
+
"name": {"type": "string"},
|
44 |
+
"notes": {"type": "string"}
|
45 |
},
|
46 |
"required": ["email"],
|
47 |
"additionalProperties": False
|
|
|
50 |
|
51 |
record_unknown_question_json = {
|
52 |
"name": "record_unknown_question",
|
53 |
+
"description": "Record a question that couldn't be answered",
|
54 |
"parameters": {
|
55 |
"type": "object",
|
56 |
"properties": {
|
57 |
+
"question": {"type": "string"}
|
58 |
},
|
59 |
"required": ["question"],
|
60 |
"additionalProperties": False
|
|
|
74 |
Path("chat_logs").mkdir(exist_ok=True)
|
75 |
|
76 |
# Download LinkedIn PDF
|
77 |
+
gdown.download("https://drive.google.com/uc?id=1xz2RowkImpI8odYv8zvKdlRHaKfILn40", "linkedin.pdf", quiet=False)
|
|
|
78 |
reader = PdfReader("linkedin.pdf")
|
79 |
self.linkedin = "".join(page.extract_text() or "" for page in reader.pages)
|
80 |
|
81 |
# Download summary.txt
|
82 |
+
gdown.download("https://drive.google.com/uc?id=1hjJz082YFSVjFtpO0pwT6Tyy3eLYYj6-", "summary.txt", quiet=False)
|
|
|
83 |
with open("summary.txt", "r", encoding="utf-8") as f:
|
84 |
self.summary = f.read()
|
85 |
|
86 |
+
self.archive_logs()
|
87 |
+
|
88 |
def system_prompt(self):
|
89 |
return f"""You are acting as {self.name}. You're answering questions on {self.name}'s website about his career, experience, and skills.
|
90 |
Be professional and conversational, as if talking to a potential employer or client.
|
|
|
131 |
full_response += delta.content
|
132 |
yield full_response
|
133 |
|
134 |
+
# Append a helpful follow-up message
|
135 |
+
full_response += "\n\n💬 Let me know if you’d like to follow up or need help connecting with Jacob."
|
136 |
+
|
137 |
self.session_log.append({"role": "assistant", "content": full_response})
|
138 |
self.save_session_log()
|
139 |
|
|
|
143 |
with open(filename, "w", encoding="utf-8") as f:
|
144 |
json.dump(self.session_log, f, indent=2)
|
145 |
|
146 |
+
def archive_logs(self):
|
147 |
+
"""Create a zip archive of all previous logs — replaceable for weekly automation"""
|
148 |
+
zip_path = "chat_logs/weekly_archive.zip"
|
149 |
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as archive:
|
150 |
+
for log_file in Path("chat_logs").glob("session_*.json"):
|
151 |
+
archive.write(log_file, arcname=log_file.name)
|
152 |
+
|
153 |
+
# Instantiate assistant
|
154 |
me = Me()
|
155 |
|
156 |
+
# Build UI
|
157 |
with gr.Blocks(title="Jacob Isaacson Chatbot") as iface:
|
158 |
with gr.Row():
|
159 |
+
gr.Image("jacob.png", width=100, show_label=False)
|
160 |
+
gr.Markdown("### Chat with Jacob Isaacson\nAsk about Jacob's background, skills, or career. \n🛡️ *All chats are logged for improvement purposes.*")
|
161 |
|
162 |
gr.ChatInterface(
|
163 |
fn=me.chat_stream,
|
164 |
chatbot=gr.Chatbot(show_copy_button=True),
|
165 |
examples=["What is Jacob's experience with AI?", "Tell me about his recent projects."],
|
166 |
+
type="messages"
|
167 |
)
|
168 |
|
169 |
if __name__ == "__main__":
|