ChatBot / app.py
Ankush05's picture
Update app.py
7dc69fc
raw
history blame
1.08 kB
import streamlit as st
import os
from transformers import pipeline
from bardapi import Bard
import os
from getvalues import getValues
from pymongo import MongoClient
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 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)
chatbot()