Spaces:
Sleeping
Sleeping
fix readme
Browse files
README.md
CHANGED
|
@@ -33,12 +33,11 @@ You can call this service from your applications:
|
|
| 33 |
|
| 34 |
```python
|
| 35 |
import requests
|
| 36 |
-
import base64
|
| 37 |
from PIL import Image
|
| 38 |
import io
|
| 39 |
|
| 40 |
# Your Hugging Face Space URL
|
| 41 |
-
API_URL = "https://YOUR-USERNAME-background-removal.hf.space/
|
| 42 |
|
| 43 |
# Read image
|
| 44 |
with open("your_image.png", "rb") as f:
|
|
@@ -47,21 +46,20 @@ with open("your_image.png", "rb") as f:
|
|
| 47 |
# Call API
|
| 48 |
response = requests.post(
|
| 49 |
API_URL,
|
| 50 |
-
files={"
|
| 51 |
timeout=60
|
| 52 |
)
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
output_image.save("output.png")
|
| 65 |
```
|
| 66 |
|
| 67 |
### Environment Variables for CloudRun Worker
|
|
|
|
| 33 |
|
| 34 |
```python
|
| 35 |
import requests
|
|
|
|
| 36 |
from PIL import Image
|
| 37 |
import io
|
| 38 |
|
| 39 |
# Your Hugging Face Space URL
|
| 40 |
+
API_URL = "https://YOUR-USERNAME-background-removal.hf.space/remove-bg"
|
| 41 |
|
| 42 |
# Read image
|
| 43 |
with open("your_image.png", "rb") as f:
|
|
|
|
| 46 |
# Call API
|
| 47 |
response = requests.post(
|
| 48 |
API_URL,
|
| 49 |
+
files={"file": ("image.png", image_bytes, "image/png")},
|
| 50 |
timeout=60
|
| 51 |
)
|
| 52 |
|
| 53 |
+
# Save result (response is PNG image)
|
| 54 |
+
output_image = Image.open(io.BytesIO(response.content))
|
| 55 |
+
output_image.save("output.png")
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Or use curl:
|
| 59 |
+
```bash
|
| 60 |
+
curl -X POST "https://YOUR-USERNAME-background-removal.hf.space/remove-bg" \
|
| 61 |
+
-F "file=@your_image.png" \
|
| 62 |
+
-o output.png
|
|
|
|
| 63 |
```
|
| 64 |
|
| 65 |
### Environment Variables for CloudRun Worker
|