How can i set a model from hugging face into streamlit


i want to create a web app where i use stable diffusion in Streamlit
how can i do that ?

Steps to reproduce

Code snippet:

add code here

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

Debug info

  • Streamlit version: (get it with $ streamlit version)
  • Python version: (get it with $ python --version)
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version:
  • Browser version:

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.


  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

Install the Hugging Face Transformers library by running pip install transformers.

import streamlit as st
from transformers import pipeline

Choose a pre-trained model from the Hugging Face model hub. (You can find a list of available models at
Load the model using the pipeline class from the Transformers library. For example, to load a sentiment analysis model:

model = pipeline("sentiment-analysis")

create a simple UI for your streamlit app:

def main():
    st.title("Hugging Face Model Demo")

    # Create an input text box
    input_text = st.text_input("Enter your text", "")

    # Create a button to trigger model inference
    if st.button("Analyze"):
        # Perform inference using the loaded model
        result = model(input_text)
        st.write("Prediction:", result[0]['label'], "| Score:", result[0]['score'])

if __name__ == "__main__":

if i deploy this app , will it be downloading the model from hugging face every other time the page is refreshed?

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