How to Integrate Diffuser/Transformer

How to Fork the Space and Deploy it:

1. Visit [] and log in to your account

2. Visit the Base Space, and click on the [Fork] button to create a duplicate of the Base Space.

3. You can either click on the [Just Fork, choose config later] or select your preferred hardware, and proceed with the payment.

It's recommended to choose "config later" if you anticipate adding more models to your Space in the future to avoid unnecessary redeployments.

In your forked Space, you can click the [Settings] button and scroll down to the Rename section to rename your Space.

Note: Please note that after you change the Space name, the Space link will also be updated. Make sure to share the new link with others as needed.

How to Change Models

In this tutorial, you will learn how to change models within your Diffuser/Transformer Space to meet your specific needs. We will be using the example of changing a model for the "Image-to-Text" task. Follow these steps:

Step 1: Choose a New Model

1.Visit the Hugging Face Model Hub at

2.In the library list, select either "Transformers" or "Diffusers," depending on your requirements.

3.In the task list, choose the specific model type you want. For this tutorial, we'll use "Image-to-Text" as an example.

Refine your search criteria to find a model that meets your requirements. Once you have identified the model you want to use, copy its name.

Step 2: Update Your Lagrange Space

1.Go to the Space that you've forked before

2.Navigate to "Files and Versions." Locate the file named "model-setting.json" and open it.

3.Inside this JSON file, replace the existing model name with the one you copied from the Hugging Face Model Hub.

4.Save the changes to the JSON file.

5.After updating the model name, redeploy your Space following Building Space

Once the deployment is complete, you can access the new model through the Inference Endpoint, which has been updated with the selected model.

import requests

API_URL = ""

def query(filename):
    with open(filename, "rb") as f:
        data =
    response =, data=data)
    return response.json()

output = query("cats.jpg")

Click here to check the Sample Space.

Last updated