Spaces:
Paused
Paused
VINU NAYAK commited on
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,14 +1,78 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Background Removal API
|
| 2 |
+
|
| 3 |
+
A simple API service that removes backgrounds from images.
|
| 4 |
+
|
| 5 |
+
## Setup
|
| 6 |
+
|
| 7 |
+
1. Install the required packages:
|
| 8 |
+
```
|
| 9 |
+
pip install -r requirements.txt
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
2. Run the server:
|
| 13 |
+
```
|
| 14 |
+
uvicorn main:app --host 0.0.0.0 --port 7860
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
The server will start on port 7860.
|
| 18 |
+
|
| 19 |
+
## API Endpoints
|
| 20 |
+
|
| 21 |
+
### GET /
|
| 22 |
+
Returns a status message indicating the API is running or redirects to the web interface.
|
| 23 |
+
|
| 24 |
+
### GET /health
|
| 25 |
+
Returns health check information about the API.
|
| 26 |
+
|
| 27 |
+
### POST /remove-bg
|
| 28 |
+
Removes the background from an uploaded image.
|
| 29 |
+
|
| 30 |
+
**Request:**
|
| 31 |
+
- Form data with a file field named "file" containing the image
|
| 32 |
+
|
| 33 |
+
**Response:**
|
| 34 |
+
- PNG image with transparent background
|
| 35 |
+
|
| 36 |
+
## Example Usage
|
| 37 |
+
|
| 38 |
+
Using curl:
|
| 39 |
+
```bash
|
| 40 |
+
curl -X POST -F "file=@your_image.jpg" http://localhost:7860/remove-bg -o result.png
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
Using Python requests:
|
| 44 |
+
```python
|
| 45 |
+
import requests
|
| 46 |
+
|
| 47 |
+
url = "http://localhost:7860/remove-bg"
|
| 48 |
+
files = {"file": open("your_image.jpg", "rb")}
|
| 49 |
+
response = requests.post(url, files=files)
|
| 50 |
+
|
| 51 |
+
with open("result.png", "wb") as f:
|
| 52 |
+
f.write(response.content)
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## Deployment on Hugging Face Spaces
|
| 56 |
+
|
| 57 |
+
This API is designed to be compatible with Hugging Face Spaces. The server runs on port 7860 by default.
|
| 58 |
+
|
| 59 |
+
To deploy to Hugging Face Spaces:
|
| 60 |
+
1. Create a new Space with the "FastAPI" SDK
|
| 61 |
+
2. Upload all these files to the Space
|
| 62 |
+
3. The API will be available at: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
|
| 63 |
+
|
| 64 |
+
Example API URL for background removal:
|
| 65 |
+
```
|
| 66 |
+
https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME/remove-bg
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### Troubleshooting Hugging Face Spaces Deployment
|
| 70 |
+
|
| 71 |
+
If you encounter issues with the deployment:
|
| 72 |
+
|
| 73 |
+
1. Check the health endpoint: `/health`
|
| 74 |
+
2. Make sure all required dependencies are installed
|
| 75 |
+
3. Verify the static directory exists and contains the index.html file
|
| 76 |
+
4. Check the Hugging Face Spaces logs for any error messages
|
| 77 |
+
|
| 78 |
+
The API is configured to provide detailed debugging information to help diagnose issues.
|