Text disappears and reappers continuously while being printed

I’m building a basic chat app. When deployed locally, it’s working perfectly, as seen here:

opera_YwNosTW2UR

But when I deploy it on a server, the text keeps flashing repeatedly.

msedge_GQ15T7ZYRU

I’ve made sure that the code is exactly thee same in both locations. Here’s the code for printing the generated text.

if genresponse != None:
                        start= time.time()
                        for chunk in genresponse['results'][0]['generated_text']:
                            if chunk == "User:" or chunk == "Stu:" or chunk == "User: " or chunk == "Stu: " :
                                messagefull += " \n"
                                time.sleep(0.05)
                                placehold.markdown(messagefull+"|")

                            else:
                                messagefull += chunk
                                time.sleep(0.05)
                                placehold.markdown(messagefull+"|")
                        
                        end = time.time()
                        placehold.markdown(messagefull)

I’m not sure why this is happening, and would appreciate any help, since I’m very new to using Streamlit.

1 Like

Hi @Amal_Sajeev

How would commenting out the time.sleep(0.05) line look, would that resolve the issue?

2 Likes

This doesn’t work. I tried eliminating that entire block and only printing the generated stream with st.write_stream, but the flashing still happens.

genresponse = model.generate_text_stream(systemprompt)
#PRINTING RESPONSE
#datalast = dataresponse
if genresponse != None:
        messagefull=st.write_stream(genresponse)

1 Like

Hi,

What model are you using to generate the text? I suspect that it may be compute intensive and so takes a while to generate the text (thus the disappearing and reappearing of text). How would replacing the model with an OpenAI API or Replicate API, would this resolve the issue (since the models are hosted on more robust servers).

1 Like

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