# How to Integrate Diffuser/Transformer

### How to Fork the Space and Deploy it:

1\. Visit \[<https://lagrange.computer/spaces>] and log in to your account

2\. Visit the [Base Space](https://lagrange.computer/spaces/0x231fe9090f4d45413474BDE53a1a0A3Bd5C0ef03/Stable-Diffusion-Base-LoRA/app), and click on the **\[Fork]** button to create a duplicate of the Base Space.

<figure><img src="https://lh6.googleusercontent.com/oRy_T_MNTSJ6bqGTJtiHK_Pw-tzBLhY3r6e1UFzPxxxxD1bh5OImd22rOktVH0Cs1iO-CW1B1-a6J8JYn0GvSy_sZn1PWvuIpNg5yHGTpTI3pgWzxh9Zrm4q2eL-iyW2AAYlgOA29FZR1LN4CGw9t3c" alt=""><figcaption></figcaption></figure>

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.

<figure><img src="https://lh5.googleusercontent.com/S2daQ_7aiKXdAxCogyBDELByzC282gzCATDRIa9vhx_0xYT8nrqYhAvu5kAvbrE5s-O1kYqzZ1jZYG9pnFYxqK8k-FfD1KFuAMh5g9GJ1GjbYtP5NxueHVCP3QUA3DO25DqUo-jSA63e6hPaJjKizzU" alt=""><figcaption></figcaption></figure>

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.*

<figure><img src="https://lh4.googleusercontent.com/cdSKmw-kdgN5Zlm2mQ05GiCantlI8hbbfc1Ahc5cp6DcU6Fw4dMlftmYWJCskoq6tAl7oB5sXuUm549WhQ9EcIHxt6RLVcnTVwt-228mqOKEZ5KDiXmZintlNr3CeUKLzw5lTksOslWfjwwRFE7Mb1U" alt=""><figcaption></figcaption></figure>

### 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 <https://huggingface.co/models>.

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

<figure><img src="https://2830694519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy5iPODl9iwLxyYirHs2D%2Fuploads%2Fm5P8HhL2R9twNBbE6NxW%2Fimage.png?alt=media&#x26;token=f8bbb977-541e-4451-82f2-e6932ee8e6f2" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2830694519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy5iPODl9iwLxyYirHs2D%2Fuploads%2FeLT8W54Id1sfFYM5Imz2%2Fimage.png?alt=media&#x26;token=1c786bc7-8def-438e-a580-c4f07445e928" alt=""><figcaption></figcaption></figure>

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.

<figure><img src="https://2830694519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy5iPODl9iwLxyYirHs2D%2Fuploads%2F0OBnan5tbsJSmjVa5zR1%2Fimage.png?alt=media&#x26;token=b77d6e9f-b032-4a99-98c2-020a51d6ec66" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2830694519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy5iPODl9iwLxyYirHs2D%2Fuploads%2FOB3ldadoSIsEVNetCbRl%2Fimage.png?alt=media&#x26;token=f103d59e-e817-44c5-aeab-d84a9b5745fd" alt=""><figcaption></figcaption></figure>

4.Save the changes to the JSON file.

5.After updating the model name, redeploy your Space following [build-space](https://docs.lagrangedao.org/mars-testnet/build-space "mention")

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

{% tabs %}
{% tab title="Python" %}

```python
import requests

API_URL = "https://24lhiquaxn.meta.crosschain.computer"


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


output = query("cats.jpg")
print(output)
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
async function query(filename) {
    const data = fs.readFileSync(filename);
    const response = await fetch(
        "https://24lhiquaxn.meta.crosschain.computer",
        {
            method: "POST",
            body: data,
        }
    );
    const result = await response.json();
    return result;
}

query("cats.jpg").then((response) => {
    console.log(JSON.stringify(response));
});
```

{% endtab %}

{% tab title="cURL" %}

```url
 curl  https://24lhiquaxn.meta.crosschain.computer \
    -X POST \
    --data-binary '@cats.jpg'
```

{% endtab %}
{% endtabs %}

Click [here](https://lagrangedao.org/spaces/0xFbc1d38a2127D81BFe3EA347bec7310a1cfa2373/api-image-to-text/app) to check the Sample Space.
