Skip to content
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

JS client take 2 #3388

Merged
merged 14 commits into from
Mar 7, 2023
Merged

JS client take 2 #3388

merged 14 commits into from
Mar 7, 2023

Conversation

pngwn
Copy link
Member

@pngwn pngwn commented Mar 6, 2023

Description

Closes #3310. Closes #3262. Closes #3263.

New API:

Initialise the client

const app = await client('some/space', space_status_callback);

Supports the following types for tyhe 'some/space' argument:

  • owner/name
  • sub-dom-ain.hf.space
  • https://sub-dom-ain.hf.space
  • https://my-own-host.com

Make a prediction

const result = await app.predict('/predict', payload);

This will return the result for simple endpoints of the first generated value for generator endpoints, regardless of whether there are a finite number of iterations or require cancellation.

Returning the first result in this manner means that generator functions will never block for longer than a simple prediction function, even if they are infinite.

Get data updates other than the initial result

For generator functions, users may be interested in data other than the initial value.

app.on('data', event => {
  event.type /// === 'data'
  event.endpoint // === '/predict' or whichever endpoint the data corresponds to
  event.data // the payload/ data
  event.fn_index // === the fn_index
})

Get status updates

Users may be interested in what their prediction is up to:

app.on('status', event => {
  event.type /// === 'status'
  event.endpoint // === '/predict' or whichever endpoint the data corresponds to
  event.status // the status for this prediction? need to double check
  event.fn_index // === the fn_index
})

To cancel a generator function:

app.cancel('/predict', optional_fn_index);

This does nothing if the function is not a generator.

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 6, 2023

🎉 The demo notebooks match the run.py files! 🎉

@gradio-pr-bot
Copy link
Collaborator

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-3388-all-demos

@pngwn pngwn marked this pull request as draft March 6, 2023 17:16
@pngwn pngwn marked this pull request as ready for review March 6, 2023 18:25
Copy link
Contributor

@julien-c julien-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't dived enough at all, but what would you think of this living (or minimally, being duplicated/exposed) in https://github.com/huggingface/huggingface.js, maybe as a @huggingface/spaces package ?

Would be quite consistent with Inference APi and Endpoints.

cc @coyotte508 @Wauplin and others

@pngwn
Copy link
Member Author

pngwn commented Mar 7, 2023

Reposting:

The client will work with any app regardless of how it is hosted, so i don't think it makes sense to require users to install a hugging face specific lib if they're only using the library and not hugging face.

I also think it makes sense to keep them separate so we can change things more easily with less red tape, gradio functions also have some features that require specific APIs.

We also use the client library in gradio itself, so we need to be able to tweak + develop locally, it is core to gradio so having it somewhere else doesn't make sense.

The hub library could include it as a dependency and wrap it but i wouldn't want to do it the other way around.

@coyotte508
Copy link

coyotte508 commented Mar 7, 2023

We can link to it in a "see also" section in the hugginface.js's main README for example?

@pngwn
Copy link
Member Author

pngwn commented Mar 7, 2023

This library isn't being published yet anyway so there is no huge rush on this, we'd like to dogfood it a little before releasing to npm.

@pngwn
Copy link
Member Author

pngwn commented Mar 7, 2023

Will probably release a 0.x at some point just to get the publish tooling sorted + tested. We'll be releasing other stuff under the gradio namespace too soonish™️.

@abidlabs
Copy link
Member

abidlabs commented Mar 7, 2023

I did one round of testing and the demos look good @pngwn. Can you go ahead and resolve the merge conflict and I'll do some more testing?

@pngwn
Copy link
Member Author

pngwn commented Mar 7, 2023

Should be okay now @abidlabs.

@abidlabs
Copy link
Member

abidlabs commented Mar 7, 2023

Looks great @pngwn! Tested a variety of demos locally and on the deployed PR Space, and they all worked, with the exception of one: chatbot_multimodal.

If you run demo/chatbot_multimodal on this branch and upload an image, you'll notice that the image does not appear:

image

The reason seems to be that the chatbot component is looking for a file at this location:

http://127.0.0.1:7870file=filepath

instead of:

http://127.0.0.1:7870/file=filepath

(notice the missing slash). This is even though the chatbot_multimodal explicitly provides a slash when creating the message. See:

history + [(f"![](/file={quote(image.name)})", "Cool pic!")]

Do you know what might be happening? This demo is working fine on main

@pngwn
Copy link
Member Author

pngwn commented Mar 7, 2023

The frontend of the chatbot replaces the link sources for a reasons that aren't entirely clear to me.

This PR changes how we handle basepaths a little.

Will fix.

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested a variety of demos and everything is working great! LGTM

@pngwn pngwn merged commit fddf376 into main Mar 7, 2023
@pngwn pngwn deleted the 3263-api branch March 7, 2023 16:36
dawoodkhan82 pushed a commit that referenced this pull request Mar 8, 2023
* start

* change api

* integrate into gradio

* log

* try this

* format

* changes

* format

* fix css

* fix file
dawoodkhan82 added a commit that referenced this pull request Mar 9, 2023
* hub telemetry

* more analytics

* format

* changelog

* Gradio Status Page  (#3331)

* add status page to error message

* changelog

* link to status page on website

* move link to the right

* merge

* merge

* Add option to display gallery in preview mode (#3345)

* Add code + api

* CHANGELOG

* dropdown (#3338)

* fix

* fixes

* format

* changelog

* Update gradio/components.py

Co-authored-by: Abubakar Abid <[email protected]>

* fix clear case

---------

Co-authored-by: Abubakar Abid <[email protected]>

* Some improvements to Flag (#3289)

* Fixes to button disable

* button

* formatting

* flagging fix

* fixes

* formatter

* changelog

* ormatting

* tests

* saving

* adding optionality for flagging

* updatest

* error catching

* updates

* changelog

* tests

* typing

* flag button

* formatting

* tests

* tests

* tests

* increased latency

* queue fix

* clear

* formatting

* fix

* fix tests

* Fix flaky external test (#3348)

* Fix flaky external test

* CHANGELOG

* Undo accidental diff

* Fix flaky external test

* CHANGELOG

* Undo accidental diff

* Remove from changelog

* Use bunny file

---------

Co-authored-by: Abubakar Abid <[email protected]>

* updates

* format

* more updates

* threading

* fixes

* Fix error when using backen_fn and custom js at the same time (#3358)

* Fix error when using backen_fn and custom js at the same time

* generate notebooks

* update changelog

* changes

---------

Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: Freddy Boulton <[email protected]>

* Fix File updating (#3375)

* Fix

* Remove line

* Add unit test

* CHANGELOG

* Remove comment

* Updated chat ui (#3370)

* test

* changes

* chagnes

* changes

* changes

* changes

* changes

* Update CHANGELOG.md

* changes

* Update demo/chatbot_multimodal/run.py

Co-authored-by: Abubakar Abid <[email protected]>

* Update demo/chatbot_simple_demo/run.py

Co-authored-by: Abubakar Abid <[email protected]>

* changes

* changes

* changes

---------

Co-authored-by: Abubakar Abid <[email protected]>

* fixes

* New Version Docs (#3376)

* [create-pull-request] automated change

* empty commit

* [create-pull-request] automated change

* empty commit

---------

Co-authored-by: abidlabs <[email protected]>
Co-authored-by: aliabd <[email protected]>

* requirements

* test requirements

* Release 3.20.1 (#3390)

* release 3.20.1

* changelog

* merge

* New Version Docs (#3392)

* [create-pull-request] automated change

* trigger ci

---------

Co-authored-by: abidlabs <[email protected]>
Co-authored-by: Abubakar Abid <[email protected]>

* merge

* Remove everything related to encryption (#3396)

* remove requirements

* deprecate encrypt

* remove flagging

* deprecate

* formatting

* lint

* Adds a Chinese translation for the `README` (#3394)

* add chinese readme

* add chinese readme

* update changelog

* fix render_readme and english readme

* generate readme

* remove template and quickstart files

* link to chinese from english

* fix assets paths

* link to english from chinese

* change file location

* fix link

* fix link

* fix link

---------

Co-authored-by: aliabd <[email protected]>

* fix bad codeblock (#3401)

* Always set queue=False if every is None for load events (#3391)

* Always set queue=False if every is None

* CHANGELOG + linting

* Move to latest release section

* changelog

---------

Co-authored-by: Abubakar Abid <[email protected]>

* JS client take 2 (#3388)

* start

* change api

* integrate into gradio

* log

* try this

* format

* changes

* format

* fix css

* fix file

* fix #3282 avoid in-place dict updates (#3405)

* fix #3282 avoid in-place dict updates

* add tests and changelog for PR3405

* Fix markdown embedded component in docs (#3410)

* revert to old md component demo

* changelog

* Added a section on security (#3408)

* security

* added section on security

* security

* changes from review

* Fix local tests (#3411)

* document embed params

* fix tests

* cleanup

* cleanup

* cleanup

* revert

* changelog

* Document web component parameters (#3407)

* document embed params

* changelog

* iframe

* fixed review changes

* requirements

* fixes

* format

* format

* requirements

---------

Co-authored-by: Abubakar Abid <[email protected]>
Co-authored-by: Ali Abdalla <[email protected]>
Co-authored-by: Freddy Boulton <[email protected]>
Co-authored-by: pngwn <[email protected]>
Co-authored-by: Jialei <[email protected]>
Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: abidlabs <[email protected]>
Co-authored-by: Uanu <[email protected]>
Co-authored-by: gitgithan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants