VINU NAYAK commited on
Commit
f35b891
·
verified ·
1 Parent(s): e0bb8ef

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +33 -84
README.md CHANGED
@@ -1,106 +1,55 @@
1
- ---
2
- title: RemBG_API
3
- emoji: 🖼️
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: docker
7
- sdk_version: 1.0.0
8
- app_file: fallback.py
9
- pinned: false
10
- ---
11
 
12
- # Background Removal API
13
-
14
- A simple API service that removes backgrounds from images.
15
 
16
  ## Setup
17
 
18
  1. Install the required packages:
19
- ```
20
  pip install -r requirements.txt
21
  ```
22
 
23
- 2. Run the server:
24
- ```
25
- uvicorn fallback:app --host 0.0.0.0 --port 7860
26
- ```
27
-
28
- The server will start on port 7860.
29
 
30
- ## API Endpoints
31
-
32
- ### GET /
33
- Returns a status message indicating the API is running or redirects to the web interface.
34
-
35
- ### GET /health
36
- Returns health check information about the API.
37
-
38
- ### POST /remove-bg
39
- Removes the background from an uploaded image.
40
 
41
- **Request:**
42
- - Form data with a file field named "file" containing the image
43
 
44
- **Response:**
45
- - PNG image with transparent background
 
 
 
 
46
 
47
- ## Example Usage
 
 
48
 
49
- Using curl:
50
  ```bash
51
- curl -X POST -F "file=@your_image.jpg" http://localhost:7860/remove-bg -o result.png
52
  ```
53
 
54
- Using Python requests:
55
  ```python
56
  import requests
57
 
58
- url = "http://localhost:7860/remove-bg"
59
- files = {"file": open("your_image.jpg", "rb")}
60
- response = requests.post(url, files=files)
 
61
 
62
- with open("result.png", "wb") as f:
63
- f.write(response.content)
64
- ```
65
 
66
- ## Deployment on Hugging Face Spaces
67
-
68
- This API is designed to be compatible with Hugging Face Spaces. The server runs on port 7860 by default.
69
-
70
- To deploy to Hugging Face Spaces:
71
- 1. Create a new Space with the "Docker" SDK
72
- 2. Upload all these files to the Space
73
- 3. The API will be available at: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
74
-
75
- Example API URL for background removal:
76
  ```
77
- https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME/remove-bg
78
- ```
79
-
80
- ### Troubleshooting Hugging Face Spaces Deployment
81
-
82
- If you encounter issues with the deployment:
83
-
84
- 1. Check the health endpoint: `/health`
85
- 2. Make sure all required dependencies are installed
86
- 3. Verify the static directory exists and contains the index.html file
87
- 4. Check the Hugging Face Spaces logs for any error messages
88
-
89
- #### Numba/Rembg Issues
90
-
91
- If you encounter issues with Numba caching or the rembg library:
92
-
93
- 1. The main.py file includes a fix that disables Numba JIT compilation
94
- 2. If issues persist, you can use the fallback.py version (currently active)
95
- ```
96
- # Update the app_file in README.md
97
- app_file: fallback.py
98
- ```
99
-
100
- And update the Dockerfile:
101
- ```
102
- # Change the CMD line in Dockerfile
103
- CMD ["uvicorn", "fallback:app", "--host", "0.0.0.0", "--port", "7860"]
104
- ```
105
-
106
- The fallback version doesn't actually remove backgrounds but provides a compatible API.
 
1
+ # RemBG API Server
 
 
 
 
 
 
 
 
 
2
 
3
+ This is a Flask-based API server that removes backgrounds from images using the rembg library.
 
 
4
 
5
  ## Setup
6
 
7
  1. Install the required packages:
8
+ ```bash
9
  pip install -r requirements.txt
10
  ```
11
 
12
+ 2. Configure the environment:
13
+ - Copy `.env.example` to `.env`
14
+ - Set your desired API key in the `.env` file
 
 
 
15
 
16
+ 3. Run the server:
17
+ ```bash
18
+ python app.py
19
+ ```
 
 
 
 
 
 
20
 
21
+ ## API Usage
 
22
 
23
+ ### Remove Background
24
+ - Endpoint: `POST /remove-bg`
25
+ - Headers:
26
+ - `X-API-Key`: Your API key
27
+ - Body: Form-data with an 'image' file
28
+ - Returns: PNG image with background removed
29
 
30
+ ### Health Check
31
+ - Endpoint: `GET /health`
32
+ - Returns: Health status of the server
33
 
34
+ ## Example Usage with cURL
35
  ```bash
36
+ curl -X POST -H "X-API-Key: your-api-key" -F "image=@path/to/your/image.jpg" http://localhost:5000/remove-bg -o output.png
37
  ```
38
 
39
+ ## Example Usage with Python
40
  ```python
41
  import requests
42
 
43
+ url = "http://localhost:5000/remove-bg"
44
+ headers = {
45
+ "X-API-Key": "your-api-key"
46
+ }
47
 
48
+ with open("input.jpg", "rb") as f:
49
+ files = {"image": f}
50
+ response = requests.post(url, headers=headers, files=files)
51
 
52
+ if response.status_code == 200:
53
+ with open("output.png", "wb") as f:
54
+ f.write(response.content)
 
 
 
 
 
 
 
55
  ```