-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot.py
59 lines (44 loc) · 1.59 KB
/
chatbot.py
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
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
import time
import random
import os
from pandasai import Agent
import pandas as pd
# def app():
# st.markdown(
# "<h1 style='text-align:center; color:#1cbc55'>CHAT WITH THE BOT</h1>", unsafe_allow_html=True)
# st.warning("FEATURE STILL UNDER DEVLOPEMENT, SORRY FOR THE INCONVINIENCE")
try:
os.environ["PANDASAI_API_KEY"] = (
"$2a$10$UWmuWvJnRiC6K2rc/RgS8.ECP5oDM07mkLF9lKqQxZRxDAV8eNYKu"
)
except:
st.warning("The Bot API is facing some issue, please try again later.")
try:
df = pd.read_csv("./data/tracks.csv")
agent = Agent(df)
print("\nChatbot Agent is ready...")
except:
st.warning("The Bot API is facing some issue, please try again later.")
def app():
def response_generator(prompt):
response = agent.chat(prompt)
return response
st.markdown(
"<h1 style='text-align:center; color:#1cbc55'>CHAT TO KNOW MORE</h1>",
unsafe_allow_html=True,
)
if "messages" not in st.session_state:
st.session_state.messages = []
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("What is up?"):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
response = st.write(response_generator(prompt=prompt))
st.session_state.messages.append({"role": "assistant", "content": response})
if __name__ == "__main__":
app()