-
Notifications
You must be signed in to change notification settings - Fork 3.6k
workflow: inference hardcoded endpoint improvements #13710
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
Open
hannahblair
wants to merge
11
commits into
main
Choose a base branch
from
workflow-task-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ab199f4
- tweak hardcoded params
hannahblair 4f4b694
tweak
hannahblair e7ceba3
Merge branch 'main' into workflow-task-improvements
hannahblair da4244c
hf oauth tweak
hannahblair b4ae3f6
add demos
hannahblair c463e9a
add oauth to frontmatter
hannahblair 40484ce
image to text text prompt
hannahblair ba449c3
fix
hannahblair 299511b
fal fix
hannahblair 2a81990
lint
hannahblair 438c55c
type
hannahblair 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| """Ask a vision-language model about an image. | ||
|
|
||
| Drop in an image, type a question, run. The VLM answers in text. Uses the | ||
| `chat_completion` schema so the workflow works with any image-text-to-text | ||
| model regardless of which Inference Provider serves it. | ||
| """ | ||
|
|
||
| import gradio as gr | ||
|
|
||
| demo = gr.Workflow(graph="workflow.json") | ||
|
|
||
| if __name__ == "__main__": | ||
| demo.launch() |
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 @@ | ||
| {"schema_version":"2","name":"Ask About an Image","runtime":{"default":"client"},"references":[{"label":"Text","inputs":[{"id":"in","label":"Text","type":"text"}],"outputs":[{"id":"out","label":"Text","type":"text"}],"width":220,"height":163,"asset_type":"text","role":"reference","id":"81cf0eab-18c0-4d14-a2ce-217e2939ff2f","x":78.4375,"y":358.40234375,"data":{"in":"","out":""}}],"operators":[{"id":"op-vlm","label":"Kimi-K3","role":"operator","kind":"model","model_id":"moonshotai/Kimi-K3","endpoint":"chat_completion","pipeline_tag":"image-text-to-text","inputs":[{"id":"image","label":"Image","type":"image","required":false},{"id":"text","label":"Prompt","type":"text","required":false}],"outputs":[{"id":"out_0","label":"Text","type":"text","output_index":0}],"width":260,"height":184,"x":380,"y":180,"data":{"out_0":"Looks like you're tucked in somewhere cozy — maybe a van or camper? I can see wood paneling, some overhead lights, and what looks like bedding. Gives off late-night, settled-in-for-the-evening vibes.\n\nWhat's up with you? Just chilling, or is something on your mind?","text":"what going on "}}],"subjects":[{"id":"subj-answer","label":"Answer","role":"subject","asset_type":"text","inputs":[{"id":"in","label":"Text","type":"text"}],"outputs":[{"id":"out","label":"Text","type":"text"}],"width":320,"height":182,"x":720,"y":180,"data":{"in":"Looks like you're tucked in somewhere cozy — maybe a van or camper? I can see wood paneling, some overhead lights, and what looks like bedding. Gives off late-night, settled-in-for-the-evening vibes.\n\nWhat's up with you? Just chilling, or is something on your mind?"}}],"edges":[{"id":"e3","from_node_id":"op-vlm","from_port_id":"out_0","to_node_id":"subj-answer","to_port_id":"in","type":"text"},{"from_node_id":"81cf0eab-18c0-4d14-a2ce-217e2939ff2f","from_port_id":"out","to_node_id":"op-vlm","to_port_id":"text","type":"text","id":"8e33634e-9bba-4457-8138-76dff0c5ef35"}],"view":{"default":"canvas"}} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Shims for `huggingface_hub` inference-provider client fragility. | ||
|
|
||
| The per-task client methods hardcode both the task string and the response key | ||
| path, so any drift in a provider's registration or response shape breaks every | ||
| caller until upstream cuts a release. Prefer fixing upstream over adding here. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import inspect | ||
| import re | ||
|
|
||
| import httpx | ||
|
|
||
| # Raised by `TaskProviderHelper._prepare_mapping_info` when the client method's | ||
| # hardcoded task doesn't match the model's provider registration. | ||
| PROVIDER_TASK_MISMATCH_RE = re.compile( | ||
| r"is not supported for task (\S+) and provider (\S+)\. " | ||
| r"Supported task: ([^.\s]+)\." | ||
| ) | ||
|
|
||
|
|
||
| def fal_ai_video_fallback(helper, response, request_params) -> bytes: | ||
| from huggingface_hub.inference._providers.fal_ai import FalAIQueueTask | ||
|
|
||
| output = FalAIQueueTask.get_response(helper, response, request_params) | ||
| d = output if isinstance(output, dict) else {} | ||
| videos = d.get("videos") if isinstance(d.get("videos"), list) else None | ||
| url = ( | ||
| (d.get("video") or {}).get("url") | ||
| or d.get("video_url") | ||
| or (videos[0].get("url") if videos else None) | ||
| ) | ||
| if not url: | ||
| raise ValueError(f"Unexpected fal-ai response shape: {output}") | ||
| return httpx.get(url, timeout=60).content | ||
|
|
||
|
|
||
| def run_via_helper(client, helper, fn, endpoint: str, clean: dict): | ||
| from huggingface_hub.inference._providers.fal_ai import FalAIQueueTask | ||
|
|
||
| input_key = next(iter(inspect.signature(fn).parameters), "inputs") | ||
| req = helper.prepare_request( | ||
| inputs=clean.pop(input_key, None), | ||
| parameters=clean, | ||
| headers=client.headers, | ||
| model=client.model, | ||
| api_key=client.token, | ||
| ) | ||
| response = client._inner_post(req) | ||
| if endpoint == "image_to_video" and isinstance(helper, FalAIQueueTask): | ||
| return fal_ai_video_fallback(helper, response, req) | ||
| return helper.get_response(response, req) |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for these other task types, should we automatically add the optional inputs? Like for vqa, we add an image, for dqa, we add a file input?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if im understanding your Q correctly, we already do via
TASK_SCHEMASinnode-library.ts. though image to text was missing the optional text prompt so ive added that inThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw for dqa we use image not file because dqa routes through
chat_completion, which only accepts types text and image_url :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather annoying UX