Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,59 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
# import pandas as pd
|
| 4 |
-
|
| 5 |
# from streamlit_option_menu import option_menu
|
| 6 |
from bardapi import Bard
|
| 7 |
# from getvalues import getValues
|
| 8 |
-
|
| 9 |
# from transformers import pipeline, Conversation
|
| 10 |
|
| 11 |
st.set_page_config(layout="wide")
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# classifyr = pipeline("zero-shot-classification")
|
| 14 |
|
| 15 |
# convo = pipeline("conversational")
|
|
@@ -19,13 +63,6 @@ st.set_page_config(layout="wide")
|
|
| 19 |
# uri = os.environ["MONGO_CONNECTION_STRING"]
|
| 20 |
# client = MongoClient(uri, tlsCertificateKeyFile="database/cert.pem")
|
| 21 |
|
| 22 |
-
# db = client["myapp"]
|
| 23 |
-
|
| 24 |
-
# col = db["reminders"]
|
| 25 |
-
|
| 26 |
-
bardkey = os.environ.get("BARD_API_KEY")
|
| 27 |
-
|
| 28 |
-
bard = Bard(token=bardkey)
|
| 29 |
|
| 30 |
# def view_rem():
|
| 31 |
# allrem = list(col.find())
|
|
@@ -33,38 +70,38 @@ bard = Bard(token=bardkey)
|
|
| 33 |
# st.dataframe(remdata)
|
| 34 |
|
| 35 |
|
| 36 |
-
def Chatbot():
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
-
Chatbot()
|
| 68 |
|
| 69 |
|
| 70 |
# def Create_Reminder():
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
# import pandas as pd
|
|
|
|
| 4 |
# from streamlit_option_menu import option_menu
|
| 5 |
from bardapi import Bard
|
| 6 |
# from getvalues import getValues
|
| 7 |
+
from pymongo import MongoClient
|
| 8 |
# from transformers import pipeline, Conversation
|
| 9 |
|
| 10 |
st.set_page_config(layout="wide")
|
| 11 |
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
#Mongo connection
|
| 15 |
+
url = os.environ["MONGO_CONNECTION_STRING"]
|
| 16 |
+
client = MongoClient(url,tlsCerificateKeyFile ="cert.pem")
|
| 17 |
+
|
| 18 |
+
#Fetch database
|
| 19 |
+
db = client["myapp"]
|
| 20 |
+
|
| 21 |
+
#Fetch collections
|
| 22 |
+
remcol = db["Reminders"]
|
| 23 |
+
usrcol = db["Users"]
|
| 24 |
+
notecol = db["Notes"]
|
| 25 |
+
|
| 26 |
+
#Connect with Bard
|
| 27 |
+
uri = os.environ["BARD_API_KEY"]
|
| 28 |
+
bard = Bard(token = uri )
|
| 29 |
+
|
| 30 |
+
#Store user bot chat messages
|
| 31 |
+
def chat_message(ques, ans):
|
| 32 |
+
chat = {
|
| 33 |
+
"user": ques,
|
| 34 |
+
"bot": ans
|
| 35 |
+
}
|
| 36 |
+
usrcol.insert_one(chat)
|
| 37 |
+
|
| 38 |
+
#Creating reminders from the described goal
|
| 39 |
+
def create_rem(ans):
|
| 40 |
+
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}")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def Chatbot():
|
| 45 |
+
st.title("chatbot")
|
| 46 |
+
if query:= st.chat_input("Describe your goal"):
|
| 47 |
+
answer = bard.get_answer(query)
|
| 48 |
+
chat_message(query, answer)
|
| 49 |
+
create_rem(answer)
|
| 50 |
+
|
| 51 |
+
with st.chat_message("assistant"):
|
| 52 |
+
st.write(answer["content"])
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Chatbot()
|
| 56 |
+
|
| 57 |
# classifyr = pipeline("zero-shot-classification")
|
| 58 |
|
| 59 |
# convo = pipeline("conversational")
|
|
|
|
| 63 |
# uri = os.environ["MONGO_CONNECTION_STRING"]
|
| 64 |
# client = MongoClient(uri, tlsCertificateKeyFile="database/cert.pem")
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# def view_rem():
|
| 68 |
# allrem = list(col.find())
|
|
|
|
| 70 |
# st.dataframe(remdata)
|
| 71 |
|
| 72 |
|
| 73 |
+
# def Chatbot():
|
| 74 |
+
# st.title("Chatbot")
|
| 75 |
+
# if user_input := st.chat_input("Describe your goal. e.g: I want to achieve this goal in this time. Be as specific and explanatory as you can."):
|
| 76 |
+
# bardans = bard.get_answer(user_input)['content']
|
| 77 |
+
# anslist = bard.get_answer(f"Make a list of this answer: \n{bardans} \nfor this goal: \n{user_input}\n\nThe list should be in two section, section 1 for all the reminders to track called Daily Routine and section 2 for all information that should be consumed to achieve the goal and stay very focused and motivated with excitement and this section is called Notes")['content']
|
| 78 |
+
# listrem = bard.get_answer(f"Act as a ToDo Reminder AI who sets reminders or daily routine based upon the daily routine provided below:\n{anslist} \n\nMake a list of reminders with exact message, time, repetation frequecy, day/s kind of neccessary detail that would be required to set a reminder notification. Make it a numeric list.")['content']
|
| 79 |
+
# # result = classifyr(user_input,candidate_labels=["reminders", "notes"])
|
| 80 |
+
# with st.chat_message("assistant"):
|
| 81 |
+
# st.write(f"What to do to achive the goal:\n{bardans}\n\nHow to do it:\n{anslist}\n\nList of Reminders you should make:\n{listrem}")
|
| 82 |
+
|
| 83 |
+
# # with st.chat_message("user"):
|
| 84 |
+
# # st.write(result["labels"][0])
|
| 85 |
|
| 86 |
+
# # if ans["labels"][0] == "reminders":
|
| 87 |
+
# # values = getValues(query.lower())
|
| 88 |
+
# # with st.chat_message("assistant"):
|
| 89 |
+
# # st.write(values)
|
| 90 |
+
# # col.insert_one(values)
|
| 91 |
|
| 92 |
|
| 93 |
+
# # elif ans["labels"][0] == "general conversation":
|
| 94 |
+
# # umsg = bard.get_answer(query)["content"]
|
| 95 |
+
# # with st.chat_message("assistant"):
|
| 96 |
+
# # st.write(umsg)
|
| 97 |
|
| 98 |
+
# # elif ans["labels"][0] == "notes":
|
| 99 |
|
| 100 |
+
# # Notes = query.lower().replace( " create a new note", "",).replace(" no new note", "")
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
+
# Chatbot()
|
| 105 |
|
| 106 |
|
| 107 |
# def Create_Reminder():
|