Downloads · 30 days
0
philschmid/laion-asthetic-endpoint
laion-asthetic-endpoint is a machine learning model from philschmid. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for generic.
This repository implements a custom task for Geonmo/laion-aesthetic-predictor for 🤗 Inference Endpoints. The code for the customized handler is in the handler.py.
Downloads · 30 days
0
Access
Public
Updated Dec 31, 2022
Repo size
3.7 MB
Likes
0
Public
Click a slice to open those files.
.pth3.7 MB · 99%
From the Hugging Face model README
This repository implements a custom task for Geonmo/laion-aesthetic-predictor for 🤗 Inference Endpoints. The code for the customized handler is in the handler.py.
This model & handker can be tested locally using the hf-endpoints-emulator.
git lfs install
git clone https://huggingface.co/philschmid/laion-asthetic-endpoint
cd laion-asthetic-endpoint
pip install -r requirements.txt
hf-endpoints-emulatorpip install hf-endpoints-emulator
hf-endpoints-emulator --handler handler.py
curl --request POST \
--url http://localhost \
--header 'Content-Type: image/jpg' \
--data-binary '@example1.jpg'
The endpoint expects the image to be served as binary. Below is an curl and python example
wget https://huggingface.co/philschmid/laion-asthetic-endpoint/resolve/main/example1.jpg -O test.jpg
curl --request POST \
--url https://{ENDPOINT}/ \
--header 'Content-Type: image/jpg' \
--header 'Authorization: Bearer {HF_TOKEN}' \
--data-binary '@test.jpg'
{"aesthetic score": 6.764713287353516}
wget https://huggingface.co/philschmid/laion-asthetic-endpoint/resolve/main/example1.jpg -O test.jpg
import json
from typing import List
import requests as r
import base64
ENDPOINT_URL=""
HF_TOKEN=""
def predict(path_to_image:str=None):
with open(path_to_image, "rb") as i:
b = i.read()
headers= {
"Authorization": f"Bearer {HF_TOKEN}",
"Content-Type": "image/jpeg" # content type of image
}
response = r.post(ENDPOINT_URL, headers=headers, data=b)
return response.json()
prediction = predict(path_to_image="test.jpg")
prediction
expected output
{"aesthetic score": 6.764713287353516}