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.