Streamlit being static

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?:face_with_hand_over_mouth:ā€}
]

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

Hi @buroperson

The formatting of the code was difficult to read, you can encapsulate the code in trip tick (```) symbol before and after the code to get something like the following:

import streamlit as st

st.write('Hello!')

It seems that the error message arises from the missing response variable. Which if not detected in the various other conditions (if and elif, it will finally resort to else) and here it seems to be using the Reply function to generate the response. Can you check that the Reply function is functioning properly in generating the necessary response.

Hope this helps!

Sir the problem is whenever I enter I query it gets into a blackout phase and then restarts itself after 1-3 seconds as shown in the
Screenshot of the query. is there any way I can solve that ā€¦ The response function is a well tested and im definately sure it doesnā€™t have any problem
Thanks.

hi sir
i want you to know that reply function is working well it doesnt have any issues
ā€¦
Is there any by which i can remove this blackout phase or reduce it ??

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.