-
Notifications
You must be signed in to change notification settings - Fork 539
More python inference snippets #1028
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6d29991
do not export internal methods
Wauplin 0288149
better snippet for document-question-answering
Wauplin 0900c99
reorder snippets alphabetically in module
Wauplin 060cd21
better snippet for automated-speech-recognition
Wauplin 6234469
better snippet for image-to-image
Wauplin 0907d8f
Add base64 import when required
Wauplin f60999b
Merge branch 'main' into more-python-inference-snippets
Wauplin cc4a24f
fix snippet + add fixtures
Wauplin 558bb97
Merge branch 'main' into more-python-inference-snippets
Wauplin c4f6394
document question answering
Wauplin 9a0ea84
ASR
Wauplin 5bbb0fd
improvements
Wauplin 2c51475
many fixes + image-to-image
Wauplin 17c2231
pass model as method arg
Wauplin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
7 changes: 7 additions & 0 deletions
7
...asks-gen/snippets-fixtures/automatic-speech-recognition/0.huggingface_hub.hf-inference.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from huggingface_hub import InferenceClient | ||
|
|
||
| client = InferenceClient( | ||
| provider="hf-inference", | ||
| api_key="api_token", | ||
| ) | ||
| output = client.automatic_speech_recognition("sample1.flac", model="openai/whisper-large-v3-turbo") |
12 changes: 12 additions & 0 deletions
12
packages/tasks-gen/snippets-fixtures/automatic-speech-recognition/1.requests.hf-inference.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import requests | ||
|
|
||
| API_URL = "https://router.huggingface.co/hf-inference/models/openai/whisper-large-v3-turbo" | ||
| headers = {"Authorization": "Bearer api_token"} | ||
|
|
||
| def query(filename): | ||
| with open(filename, "rb") as f: | ||
| data = f.read() | ||
| response = requests.post(API_URL, headers=headers, data=data) | ||
| return response.json() | ||
|
|
||
| output = query("sample1.flac") |
4 changes: 2 additions & 2 deletions
4
...sks-gen/snippets-fixtures/conversational-llm-non-stream/0.huggingface_hub.hf-inference.py
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
4 changes: 2 additions & 2 deletions
4
...s/tasks-gen/snippets-fixtures/conversational-llm-non-stream/0.huggingface_hub.together.py
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.