-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider using huggingface_hub library for Inference #42
Comments
@Wauplin Thanks for your practical suggestion, we'll incorporate it into the plan! |
Just to be sure, not all tasks huggingface_hub are supported? @Wauplin |
@tricktreat all tasks that the Inference API on the Hub support are supported by this client (it's "just" a wrapper around If you see have feedback on the InferenceAPI client itself, please let me know. I'd glad to improve it if needed :) |
@Wauplin Thanks. I simply tried the image-to-image task and got {'error': 'Task image-to-image is invalid'}. I think maybe not all tasks are supported. import io
from diffusers.utils import load_image
from huggingface_hub.inference_api import InferenceApi
def image_to_bytes(img_url):
img_byte = io.BytesIO()
load_image(img_url).save(img_byte, format="jpeg")
img_data = img_byte.getvalue()
return img_data
inference = InferenceApi("lambdalabs/sd-image-variations-diffusers", token="****")
result = inference(data=image_to_bytes("https://raw.githubusercontent.com/justinpinkney/stable-diffusion/main/assets/im-vars-thin.jpg"))
print(result) I also checked the code and here seems to be the currently supported tasks. |
Oh right, thanks for noticing! This list is out of date then. I created an issue on
|
Thanks for the reminder. I've edited it. |
@tricktreat You really need to revoke it, i.e. create a new one. You can do that in your settings by clicking on Manage > Invalidate and refresh. You'll need to update it in the applications you have but it'll be safer this way. On Github even when you edit a comment the previous version of the text can be accessed (if you see the little arrow on the right of edited in your comment). So your token is still visible to everyone at the moment 😕 |
@Wauplin Thanks again! I was negligent about this. I have now completed the token reset according to your instructions. |
In
awesome_chat.py
, you implement the inference methodhuggingface_model_inference
(that uses the Hugging Face Hub under the hood) usingrequests
and custom code. One thing you can do to deduplicate some code is to usehuggingface_hub
library and in particular itsInferenceAPI
class. You can find a guide here on how to use it.For example, you can replace:
by
Some advantages of using
huggingface_hub
are:huggingface-cli login
, the token is automatically retrievedDisclaimer: I am a maintainer of
huggingface_hub
. If you need any help with the integration, I'd be happy to help! 😃The text was updated successfully, but these errors were encountered: