File size: 4,750 Bytes
2023b16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# SM4LL-VTON Demo API – cURL Usage Guide

This document describes how to interact with the SM4LL-VTON Gradio app via HTTP API using `cURL` commands. The app exposes a `/gradio_api/call/generate` endpoint for programmatic access to the virtual try-on functionality.

---

## Base URL

This is the current deployed endpoint:
```
https://sm4ll-vton-sm4ll-vton-demo.hf.space/gradio_api/call/generate
```

---

## Main Endpoint: `/gradio_api/call/generate`

### Description
Submit a request to generate a virtual try-on result using a base image (person), a product image (garment), and a workflow type. Optionally, a mask image can be provided.

### HTTP Method
`POST`

### Endpoint

```
https://sm4ll-vton-sm4ll-vton-demo.hf.space/gradio_api/call/generate
```

It should be changed to the correct domain once a Gradio instance is working on YourMirror.io

### Request Format
- Content-Type: `application/json`
- Required fields in the `data` array:
  - `data[0]`: Base image (object: `{ "path": "<url or file path>", "meta": {"_type": "gradio.FileData"} }`)
  - `data[1]`: Product image (object: `{ "path": "<url or file path>", "meta": {"_type": "gradio.FileData"} }`)
  - `data[2]`: Workflow type (string: `eyewear`, `footwear`, `dress`, or `top`)
  - `data[3]`: Mask image (object as above, or `null` if not used)

### Example cURL Request
```
curl -X POST "https://sm4ll-vton-sm4ll-vton-demo.hf.space/gradio_api/call/generate" \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {"path": "base_image_url.jpg", "meta": {"_type": "gradio.FileData"}},
      {"path": "product_image_url.jpg", "meta": {"_type": "gradio.FileData"}},
      "eyewear",
      null
    ]
  }'
```
- Replace `base_image_url.jpg` and `product_image_url.jpg` with the URLs or file paths to your images. (For local files, you must first upload them to a public URL or use Gradio's temp storage)
- For other workflow types, use `footwear`, `dress`, or `top` for `data[2]`.
- For the optional mask image, use the same object format as above, or set to `null`.

---

#### Accepted Workflow Types

Currently, the accepted workflow types and their corresponding models are:
- eyewear: sunglassesVTON
- footwear: footwearVTON
- dress: fullbodyVTON
- top: topgarmentVTON

Future available types and models will be:
- bottom: bottomgarmentVTON
- lookbook: lookbookVTON

---

## Response
- On success: Returns a JSON object with a `data` field containing a base64-encoded PNG image of the result.
- On error: Returns a JSON object with an `error` field describing the issue (e.g., rate limit, NSFW content, missing images).

---

### Example Success Response
```
{
  "data": [
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
  ],
  "is_generating": false, ...
}
```

### Example Error Response
```
{
  "error": "Product image contains inappropriate content. Please use a different image."
}
```

---

#### Requesting a processed result

To request a process result, you need to retrieve the event_id from the initial cURL request's responde.
For a XYZ event_id, you then need to construct a new cURL request:

```
curl -N "https://sm4ll-vton-sm4ll-vton-demo.hf.space/gradio_api/call/generate/XYZ"
```

The responde will be in the following form:

```
event: heartbeat
data: null

event: heartbeat
data: null

[...]

event: complete
data: [{"path": "path/to/tmp/gradio/storage", "url": "url/of/resulting/image", "size": null, "orig_name": "image.webp", "mime_type": null, "is_stream": false, "meta": {"_type": "gradio.FileData"}}]
```

You can then download the resulting image by using a new cURL command or any other way to download images from URLs, referencing the url/of/resulting/image obtained in the previous step via cURL -N. For example:

```
curl -o result.png "url/of/resulting/image"
```

---

#### With Optional Mask Image
```
curl -X POST "https://sm4ll-vton-sm4ll-vton-demo.hf.space/gradio_api/call/generate" \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {"path": "base_image_url.jpg", "meta": {"_type": "gradio.FileData"}},
      {"path": "product_image_url.jpg", "meta": {"_type": "gradio.FileData"}},
      "dress",
      {"path": "mask_image_url.png", "meta": {"_type": "gradio.FileData"}}
    ]
  }'
```

---

## Notes
- **Rate Limiting:** Max 30 requests per IP per hour. Exceeding this will return an error.
- **NSFW Filter:** Product images are checked for explicit content and may be rejected.
- **Supported Formats:** JPG, JPEG, PNG, WEBP (GIF/AVIF not supported).
- **Authentication:** No authentication is required for public Hugging Face Spaces. If deployed privately, include the necessary headers/tokens.
- **Image Upload:** Images must be accessible via a public URL or sent to Gradio's temporary storage.