Test / app.py
CosmoAI's picture
Update app.py
5864548
raw
history blame
1.14 kB
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()