guys im trying to create a chatbot using python
it is working well but i have a serious problem
before i go here’s my code
if “messages” not in st.session_state.keys(): # Initialize the chat message history
st.session_state.messages = [
{“role”: “assistant”, “content”: “Hello how are you?”}
]
3.3. Load and index data
if prompt := st.chat_input(“Enter a message✍”): # Prompt for user input and save to chat history
st.session_state.messages.append({“role”: “user”, “content”: prompt})
for message in st.session_state.messages: # Display the prior chat messages
with st.chat_message(message[“role”]):
st.write(message[“content”])
if st.session_state.messages[-1][“role”] != “assistant”:
with st.chat_message(“assistant”):
with st.spinner(“Thinking…”):
prompt=prompt.lower()
if ‘uwu’ in prompt:
print(‘ahem’)
response=‘hahaha’
elif ‘your name’ in prompt:
response=“You can call me Alvin👍”
elif 'hello' in prompt:
reslist = ['Hello dude how are you?', 'Heyyyy', 'Hello Cortex at your service',
'How may I help you?', 'How are you doing?',
'Hello! What are we going to do today??', 'Good day, how may I assist you?',
'Welcome, how can I be of service?', 'Greetings, how may I help you today?',
'Hello, how may I be of assistance to you?',
'Pleased to meet you, how can I support you?']
respons = random.choice(reslist)
r=respons+'✌'
response=r
elif 'open' in prompt:
if 'chrome' in prompt:
webbrowser.open_new('https://www.google.com/')
elif 'youtube' in prompt:
webbrowser.open_new('https://www.youtube.com/')
elif 'amazon' in prompt:
webbrowser.open_new('https://www.amazon.in/')
elif 'github' in prompt:
webbrowser.open_new('https://github.com/')
elif 'stackoverflow' in prompt:
webbrowser.open_new('https://stackoverflow.com/')
elif 'chatgpt' in prompt:
webbrowser.open_new('https://chat.openai.com/')
elif 'gmail' in prompt:
webbrowser.open_new('https://gmail.com/')
# elif ''
elif 'close' in prompt:
if 'chrome' in prompt:
response='Closing chrome❎'
os.system("taskkill /im chrome.exe /f")
elif 'whatsapp' in prompt:
response='Closing whatsapp❎'
os.system("taskkill /im Whatsapp.exe /f")
elif 'discord' in prompt:
response='Closing discord❎'
os.system("taskkill /im Discord.exe /f")
elif 'vs code' in prompt:
response='closing vs code❎'
os.system("taskkill /im Code.exe /f")
# elif 'joke' or 'make me laugh' in prompt:
# response=pyjokes.get_joke(language='en',category='all')
elif 'time' in prompt:
res = datetime.datetime.now().strftime("%H:%M %p")
rez='The current time is ' + res + '🕙'
response=rez
elif 'search' in prompt:
query=prompt.replace('search', ' ')
query=prompt.replace('google',' ')
query=prompt.replace('alvin',' ')
query=prompt.replace('bot',' ')
url = f"https://www.google.com/search?&q={query}"
webbrowser.open_new_tab(url)
# x=
response='Performing google search for ',query,'🔎'
elif 'play' in prompt:
query=prompt.replace('play', '')
query=prompt.replace('youtube','')
query=prompt.replace('alvin','')
query=prompt.replace('bot','')
response='searching on youtube 🫡'
url = f"https://www.youtube.com/results?search_query={query}&aq=0"
webbrowser.open_new(url)
# elif 'jai shree ram'
else:
emoji=random.choice(random_emoji_list)
re = Reply(prompt)
response=re+emoji
st.write(response)
message = {"role": "assistant", "content": response}
st.session_state.messages.append(message)
THe problem is my chat bot become static after i gave it prompt and black out and re runs and shows the result … Here’s
while entering the query
and here’s when query is done
how can i make it running for infinite?? so that it doesnt blacks out when used…
Please resolve my issue guys