VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/deploy-a-machine-learning-model-using-streamlit-library/

⇱ Deploy an AI Model using Streamlit Library - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Deploy an AI Model using Streamlit Library

Last Updated : 11 May, 2026

Streamlit is an open-source Python library designed to make it easy for developers and data scientists to turn Python scripts into fully functional web applications without requiring any front-end development skills. It allows us to quickly prototype and deploy interactive AI-powered apps directly from our local machine or the cloud.

Implementation

Step 1: Install dependencies

We will install the required dependencies for our model such as streamlit, google-generativeai.

Step 2: Set Up API Key

We need to create a environment file named .env in project directory to store our API Key.

Step 3: Build the Model

Now we will build our model:

  • Environment Setup: The .env file stores the API key securely, loaded with dotenv.
  • Model Initialization: The Gemini model "models/gemini-2.5-flash" is loaded using Google’s GenAI SDK.
  • Session Management: st.session_state ensures chat history persists during interaction.
  • Real-Time Interaction: Users type queries and responses are fetched dynamically from Gemini.
  • Auto Refresh: st.rerun() refreshes the app interface after each user message.

Step 4: Run the Streamlit App

We will start the Streamlit server and it will open our chatbot model in browser. The default URL is usually http://localhost:8501.

Output:

👁 result
Result

The source code can be downloaded from here.

Advantages

  • Rapid Deployment: Streamlit makes it effortless to transform simple Python scripts into interactive web apps which is perfect for quick AI demos or prototypes.
  • Intelligent AI Responses: Integrating Google Gemini ensures the model provides human-like, context-aware answers with exceptional reasoning and creativity.
  • Interactive User Interface: Streamlit offers dynamic UI components like text inputs, buttons and markdowns to build engaging, chat-style AI interfaces.
  • Easy Integration & Scalability: The architecture can be easily extended, allowing developers to connect databases, APIs or even train custom models for specialized tasks.
Comment