Skip to content

Commit

Permalink
Release v1.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenglongMa committed Jan 17, 2025
1 parent 01b61b6 commit 11cb291
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ In this version, we have made the following changes:
- For example, `stone -i ./path/to/images/ -p yadon-ostfeld`.
* The default palette `perla` is used for color images, and the `bw` palette is used for black/white
images.
2.**NEW!**: We have added some new use cases like Web API based projects in the documentation.

</details>

Expand Down
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
[![GitHub License](https://img.shields.io/github/license/ChenglongMa/SkinToneClassifier)](https://github.com/ChenglongMa/SkinToneClassifier/blob/main/LICENSE)
[![youtube](https://img.shields.io/badge/YouTube-Skin_Tone_Classifier-FF0000?logo=youtube)](https://youtube.com/playlist?list=PLYRpHlp-9V_E5ZLhW1hbNaVjS5Zg6b6kQ&si=ezxUR7McUbZa4clT)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1k-cryEZ9PInJRXWIi17ib66ufYV2Ikwe?usp=sharing)
[![Discord](https://img.shields.io/discord/1217972508683407422)](https://discord.gg/nnt3YGUR)
[![GitHub Repo stars](https://img.shields.io/github/stars/ChenglongMa/SkinToneClassifier)](https://github.com/ChenglongMa/SkinToneClassifier)

An easy-to-use library for skin tone classification.
Expand Down Expand Up @@ -527,7 +526,7 @@ system.

#### 10. Used as a library by importing into other projects

You can refer to the following code snippet:
You can refer to [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1k-cryEZ9PInJRXWIi17ib66ufYV2Ikwe?usp=sharing) or the following code snippet:

```python
import stone
Expand Down Expand Up @@ -581,6 +580,71 @@ The `result_json` will be like:
}
```

## 11. Used in a FAST API project

`stone` can be used in a FAST API project to classify the skin tone of the uploaded image(s) via `POST` method.

Please refer to the following code snippet:

```python
# Description: This is a simple FastAPI server that receives an image file
# and processes it using the skin-tone-classifier library.

# requirements.txt:
# fastapi
# uvicorn
# skin-tone-classifier
# python-multipart

# Run the server:
# uvicorn main:app --reload

from typing import Literal

import stone
from fastapi import FastAPI, UploadFile, HTTPException
from fastapi.responses import JSONResponse

app = FastAPI()


@app.post("/stone")
async def process_image(
image_file: UploadFile,
image_type: Literal["auto", "color", "bw"] = "auto",
tone_palette: list = None,
tone_labels: list = None,
# other parameters...
):
image_data = await image_file.read()
temp_file_path = "/tmp/temp_image.jpg"
with open(temp_file_path, "wb") as temp_file:
temp_file.write(image_data)
try:
result = stone.process(
temp_file_path,
image_type=image_type,
tone_palette=tone_palette,
tone_labels=tone_labels,
# other parameters...
)
result = JSONResponse(content=result)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
return result
```

To run the demo, please follow these steps:

1. Install required packages:
* skin-tone-classifier
* [fastapi](https://fastapi.tiangolo.com/)
* [uvicorn](https://www.uvicorn.org/)
* [python-multipart](https://pypi.org/project/python-multipart/)
2. Run the server:
`uvicorn main:app --reload`
3. You can refine the implementation according to your project requirements.
4. Finally, you can use [Postman](https://www.postman.com/) or other HTTP Clients to test the API.

# Citation

Expand Down

0 comments on commit 11cb291

Please sign in to comment.