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