Why does my Streamlit app show as running but only triggers background execution when I interact with the page especially when using FastAPI for the generative AI part

0 votes
With the help of code can you tell me Why does my Streamlit app show as 'running' but only triggers background execution when I interact with the page, especially when using FastAPI for the generative AI part?
Mar 12 in Generative AI by Ashutosh
• 23,230 points
41 views

1 answer to this question.

0 votes

Streamlit’s reactive model only executes code on user interaction—use st.cache_data or st.cache_resource to manage background calls, and ensure FastAPI requests run on app start if needed.

Here is the code snippet you can refer to:

In the above code we are using the following key points:

  • Uses st.cache_data to fetch FastAPI data only once unless manually refreshed.
  • Fetches initial data when the app starts without user interaction.
  • Allows user-driven updates with a button click.
  • Handles FastAPI response errors gracefully.
Hence, Streamlit’s lazy execution model only triggers code on interaction unless caching is used—this ensures background calls to FastAPI happen on app startup and only refresh when needed.
answered Mar 12 by syed

Related Questions In Generative AI

0 votes
1 answer

What are the best open-source libraries for AI-generated audio or music?

Top five open-source libraries, each with a ...READ MORE

answered Nov 5, 2024 in ChatGPT by rajshri reddy

edited Nov 8, 2024 by Ashutosh 529 views
0 votes
1 answer
0 votes
1 answer

What are the key challenges when building a multi-modal generative AI model?

Key challenges when building a Multi-Model Generative ...READ MORE

answered Nov 5, 2024 in Generative AI by raghu

edited Nov 8, 2024 by Ashutosh 260 views
0 votes
1 answer

How do you integrate reinforcement learning with generative AI models like GPT?

First lets discuss what is Reinforcement Learning?: In ...READ MORE

answered Nov 5, 2024 in Generative AI by evanjilin

edited Nov 8, 2024 by Ashutosh 283 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP