How to implement a spinner while waiting for the response

It seems there are some issues with using while loops in st.

I wanted a simple feature where when I wait for a reponse from API. display a spinner. But I cannot quite figure out how to wrap around it.
for example I might use

with container
response = call_steamship(prompt, context)
while not response:
container.spinner(waiting")
It seems the while part will never get executed. And also it seems that streamlit does not natively support async. Is there any way to achieve what I want?

Just by looking your unformatted code, it is not totally clear to me what you want. I don’t uderstand why you are using a container or a while loop.

I wanted a simple feature where when I wait for a reponse from API. display a spinner.

Usually you would do something like this:

with st.spinner("waiting"):
    response = call_steamship(prompt, context)

If that doesn’t work for you for some reason, you’ll need to provide more context. If call_streamlit is async, then you need to await it, I guess. That is how you usually wait for async functions to provide a response.

thank you! it worked

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