CosmoAI commited on
Commit
5864548
1 Parent(s): 34bd50f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -3,20 +3,44 @@ import os
3
  from bardapi import Bard
4
  from pymongo import Mongoclient
5
 
6
-
7
  url = os.environ["MONGO_CONNECTION_STRING"]
8
  client = MongoClient(url,tlsCerificateKeyFile ="cert.pem")
9
 
 
 
 
 
 
 
 
 
 
10
  uri = os.environ["BARD_API_KEY"]
11
  bard = Bard(token = uri )
12
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def Chatbot():
14
  st.title("chatbot")
15
- if query:= st.chat_input("Enter your message"):
16
- umsg = bard.get_answer(query)
 
 
17
 
18
  with st.chat_message("assistant"):
19
- st.write(umsg["content"])
 
20
 
21
  Chatbot()
22
 
 
3
  from bardapi import Bard
4
  from pymongo import Mongoclient
5
 
6
+ #Mongo connection
7
  url = os.environ["MONGO_CONNECTION_STRING"]
8
  client = MongoClient(url,tlsCerificateKeyFile ="cert.pem")
9
 
10
+ #Fetch database
11
+ db = client["myapp"]
12
+
13
+ #Fetch collections
14
+ remcol = db["Reminders"]
15
+ usrcol = db["Users"]
16
+ notecol = db["Notes"]
17
+
18
+ #Connect with Bard
19
  uri = os.environ["BARD_API_KEY"]
20
  bard = Bard(token = uri )
21
 
22
+ #Store user bot chat messages
23
+ def chat_message(ques, ans):
24
+ chat = {
25
+ "user": ques,
26
+ "bot": ans
27
+ }
28
+ usrcol.insert_one(chat)
29
+
30
+ #Creating reminders from the described goal
31
+ def create_rem(ans):
32
+ remlist = bard.get_answer(f"Create a daily routine to achieve this goal below and make a list of reminders with values for reminder_message, time, repetition, days\n\nGoal = {ans}")
33
+
34
  def Chatbot():
35
  st.title("chatbot")
36
+ if query:= st.chat_input("Describe your goal"):
37
+ answer = bard.get_answer(query)
38
+ chat_message(query, answer)
39
+ create_rem(answer)
40
 
41
  with st.chat_message("assistant"):
42
+ st.write(answer["content"])
43
+
44
 
45
  Chatbot()
46