Open
Conversation
Collaborator
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
jeffboudier
reviewed
Nov 25, 2024
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Image Size**: While there's no strict limit on image dimensions, it's recommended to resize large images before sending them to reduce bandwidth usage and processing time. |
Member
There was a problem hiding this comment.
is there a recommended range of image dimensions that makes sense for most multimodal models?
alvarobartt
approved these changes
Nov 25, 2024
Comment on lines
+28
to
+57
| * Using a URL | ||
| ```python | ||
| from huggingface_hub import InferenceClient | ||
| import base64 | ||
|
|
||
| client = InferenceClient(base_url="http://localhost:8080", api_key="-") | ||
|
|
||
| # Using a URL | ||
| image_url = "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" | ||
| chat_completion = client.chat.completions.create( | ||
| messages=[ | ||
| { | ||
| "role": "user", | ||
| "content": [ | ||
| { | ||
| "type": "text", | ||
| "text": "Describe this image in detail.", | ||
| }, | ||
| { | ||
| "type": "image_url", | ||
| "image_url": {"url": image_url}, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| temperature=0.7, | ||
| max_tokens=128, | ||
| ) | ||
| print(chat_completion.choices[0].message.content) | ||
| ``` |
Member
There was a problem hiding this comment.
Suggested change
| * Using a URL | |
| ```python | |
| from huggingface_hub import InferenceClient | |
| import base64 | |
| client = InferenceClient(base_url="http://localhost:8080", api_key="-") | |
| # Using a URL | |
| image_url = "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" | |
| chat_completion = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": [ | |
| { | |
| "type": "text", | |
| "text": "Describe this image in detail.", | |
| }, | |
| { | |
| "type": "image_url", | |
| "image_url": {"url": image_url}, | |
| }, | |
| ], | |
| }, | |
| ], | |
| temperature=0.7, | |
| max_tokens=128, | |
| ) | |
| print(chat_completion.choices[0].message.content) | |
| ``` | |
| ##### Using a URL | |
| ```python | |
| from huggingface_hub import InferenceClient | |
| import base64 | |
| client = InferenceClient(base_url="http://localhost:8080", api_key="-") | |
| image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png" | |
| chat_completion = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": [ | |
| { | |
| "type": "text", | |
| "text": "Describe this image in detail.", | |
| }, | |
| { | |
| "type": "image_url", | |
| "image_url": {"url": image_url}, | |
| }, | |
| ], | |
| }, | |
| ], | |
| temperature=0.7, | |
| max_tokens=128, | |
| ) | |
| print(chat_completion.choices[0].message.content) |
| client = OpenAI(base_url="http://localhost:8080/v1/", api_key="-") | ||
|
|
||
| # Using a URL or base64-encoded image | ||
| image_url = "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" # or your base64 data URL |
Member
There was a problem hiding this comment.
Same here, to use a Hugging Face image instead (in case the other link is eventually broken / not working):
Suggested change
| image_url = "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" # or your base64 data URL | |
| image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png" # or your base64 data URL |
| }, | ||
| { | ||
| "type":"image_url", | ||
| "image_url":{"url":"https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"} |
Member
There was a problem hiding this comment.
Same here:
Suggested change
| "image_url":{"url":"https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"} | |
| "image_url":{"url":"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png"} |
| print(chat_completion.choices[0].message.content) | ||
| ``` | ||
|
|
||
| * Using a local image (base64 encoded) |
Member
There was a problem hiding this comment.
Suggested change
| * Using a local image (base64 encoded) | |
| ##### Using a local image (base64 encoded) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.