ChatBot / app.py
Ankush05's picture
Update app.py
9b13e73
import streamlit as st
import os
from transformers import pipeline
from bardapi import Bard
import os
from getvalues import getValues
from pymongo import MongoClient
from streamlit_option_menu import option_menu
import pandas as pd
if "user" not in st.session_state:
st.session_state.user = "Guest"
uri = os.environ.get("MONGO_CONNECTION_STRING")
conn = MongoClient(uri, tlsCertificateKeyFile="database/cert.pem")
db = conn["myapp"]
col = db["reminders"]
bardkey = os.environ.get("BARD_API_KEY")
bard = Bard(token=bardkey)
classifi = pipeline(model="facebook/bart-large-mnli")
def view_rem():
allrem = list(col.find())
remdata = pd.DataFrame(allrem)
st.dataframe(remdata)
def chatbot():
st.title("ChatBot")
if query := st.chat_input("Enter your message"):
ans = classifi(query, candidate_labels=["Reminder", "General Conversation"])
if ans["labels"][0] == "Reminder":
values = getValues(query.lower())
with st.chat_message("assistant"):
st.write(values)
col.insert_one(values)
elif ans["labels"][0] == "General Conversation":
umsg = bard.get_answer(message)["content"]
with st.chat_message("assistant"):
st.write(umsg)
if st.session_state.user == "Guest":
with st.sidebar:
selected = option_menu(None, options=["Chatbot", "View Reminders"])
if selected == "Chatbot":
chatbot()
elif selected == "View Reminders":
view_rem()