jisaacso219 commited on
Commit
d99b8a5
·
verified ·
1 Parent(s): e8d5194

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -15,6 +15,9 @@ load_dotenv(override=True)
15
  def push(text):
16
  try:
17
  Path("chat_logs").mkdir(exist_ok=True)
 
 
 
18
  requests.post(
19
  "https://api.pushover.net/1/messages.json",
20
  data={
@@ -27,20 +30,38 @@ def push(text):
27
  print(f"Pushover error: {e}")
28
 
29
  def record_user_details(email, name="Name not provided", notes="not provided"):
30
- latest_log = "\n".join([
 
 
 
31
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
32
  for entry in me.session_log[-6:]
33
  ])
34
- msg = f"[New Contact]\nName: {name}\nEmail: {email}\nNotes: {notes}\n\nRecent Chat:\n{latest_log}"
 
 
 
 
 
 
 
35
  push(msg)
36
  return {"recorded": "ok"}
37
 
38
  def record_unknown_question(question):
39
- latest_log = "\n".join([
 
 
 
40
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
41
  for entry in me.session_log[-6:]
42
  ])
43
- msg = f"[Unknown Question]\nQ: {question}\n\nRecent Chat:\n{latest_log}"
 
 
 
 
 
44
  push(msg)
45
  return {"recorded": "ok"}
46
 
@@ -202,4 +223,3 @@ with gr.Blocks(title="Jacob Isaacson Chatbot") as iface:
202
  if __name__ == "__main__":
203
  iface.launch()
204
 
205
-
 
15
  def push(text):
16
  try:
17
  Path("chat_logs").mkdir(exist_ok=True)
18
+ keep_path = Path("chat_logs/.keep")
19
+ if not keep_path.exists():
20
+ keep_path.touch()
21
  requests.post(
22
  "https://api.pushover.net/1/messages.json",
23
  data={
 
30
  print(f"Pushover error: {e}")
31
 
32
  def record_user_details(email, name="Name not provided", notes="not provided"):
33
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
34
+ filename = f"chat_logs/session_{timestamp}.json"
35
+ latest_log = "
36
+ ".join([
37
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
38
  for entry in me.session_log[-6:]
39
  ])
40
+ with open(filename, "w", encoding="utf-8") as f:
41
+ json.dump(me.session_log, f, indent=2)
42
+ msg = f"[New Contact]
43
+ Name: {name}
44
+ Email: {email}
45
+ Notes: {notes}
46
+
47
+ 🔗 View log: {filename}"
48
  push(msg)
49
  return {"recorded": "ok"}
50
 
51
  def record_unknown_question(question):
52
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
53
+ filename = f"chat_logs/session_{timestamp}.json"
54
+ latest_log = "
55
+ ".join([
56
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
57
  for entry in me.session_log[-6:]
58
  ])
59
+ with open(filename, "w", encoding="utf-8") as f:
60
+ json.dump(me.session_log, f, indent=2)
61
+ msg = f"[Unknown Question]
62
+ Q: {question}
63
+
64
+ 🔗 View log: {filename}"
65
  push(msg)
66
  return {"recorded": "ok"}
67
 
 
223
  if __name__ == "__main__":
224
  iface.launch()
225