File size: 1,132 Bytes
26bc5a4
dea421c
26bc5a4
 
dea421c
a594e6c
26bc5a4
34bd50f
c9e6e83
a594e6c
 
 
 
 
 
 
 
 
26bc5a4
 
c814baf
a594e6c
 
 
 
 
 
 
 
 
 
 
 
c9e6e83
26bc5a4
a594e6c
 
 
 
c9e6e83
5001006
 
a594e6c
c9e6e83
aea51ec
c814baf
e6aa206
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st 
import os
from bardapi import Bard 
from pymongo import Mongoclient

#Mongo connection
url = os.environ["MONGO_CONNECTION_STRING"]
client = MongoClient(url,tlsCerificateKeyFile ="cert.pem")

#Fetch database 
db = client["myapp"]

#Fetch collections
remcol = db["Reminders"]
usrcol = db["Users"]
notecol = db["Notes"]

#Connect with Bard
uri = os.environ["BARD_API_KEY"]
bard = Bard(token = uri )

#Store user bot chat messages
def chat_message(ques, ans):
    chat = {
            "user": ques,
            "bot": ans
        }
    usrcol.insert_one(chat)

#Creating reminders from the described goal
def create_rem(ans):
    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}")

def Chatbot():
    st.title("chatbot")
    if query:= st.chat_input("Describe your goal"):
        answer = bard.get_answer(query)
        chat_message(query, answer)
        create_rem(answer)

        with st.chat_message("assistant"):
            st.write(answer["content"])


Chatbot()