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

Gradio components in gr.Chatbot() #8131

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open

Conversation

dawoodkhan82
Copy link
Collaborator

Description

Use Image, Audio, Video, Gallery, and Plot components in the chatbot.

Closes: #(issue)

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Apr 29, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/5f3321bacc9ecbd8b5fb4017a2d3810478662d4d/gradio-4.31.5-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@5f3321bacc9ecbd8b5fb4017a2d3810478662d4d#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Apr 29, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/chatbot minor
@gradio/image minor
@gradio/multimodaltextbox minor
@gradio/plot minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Gradio components in gr.Chatbot()

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

dawoodkhan82 and others added 24 commits April 29, 2024 17:33
* Add `pull_request.branches.main` as a trigger of the `publish` workflow

* [WIP] Comment out the publish steps

* Package and upload the NPM package for debug

* Skip the copy_frontend.py hook in the Lite build

* add changeset

* [WIP] Show gradio files

* [WIP] Show gradio files

* Comment out installing the gradio and gradio_client libraries

* Restore installing gradio_client because it's used by `python js/_website/generate_jsons/generate.py` that follows

* Restore installing gradio because it's used by `python js/_website/generate_jsons/generate.py` that follows

* Add code

* Revert "[WIP] Show gradio files"

This reverts commit e15fef2.

* Build the gradio wheel with the custom lite target

* add changeset

* Revert "[WIP] Show gradio files"

This reverts commit aef053f.

* Revert "Skip the copy_frontend.py hook in the Lite build"

This reverts commit ca296d0.

* Update .github/actions/install-frontend-deps/action.yml for hatch installation

* [WIP] Fix test-functional.yml and .github/actions/install-all-deps/action.yml to call the setup actions in this branch

* Revert "[WIP] Fix test-functional.yml and .github/actions/install-all-deps/action.yml to call the setup actions in this branch"

This reverts commit 571823b.

* Comment-in lines in publish.yml

* Move Lite build from publish.yml to deploy-spaces.yml

* Use the build_lite option of install-all-deps instead of running the build command

* [TMP] Change the branch of action files

* Fix the hatch Lite build setting

* Return pnpm pack to deploy-space

* Revert "[TMP] Change the branch of action files"

This reverts commit fe4e1c8.

* Remove dependencies for lite build

* [TMP] Change the branch of action files

* Revert "Remove dependencies for lite build"

This reverts commit 856a858.

* Install packaging>=23.2

* [TMP] Show packaging version

* Fix pip install

* Fix

* Uninstall packaging once

* Use `pip install -U` instead of uninstalling the exiting version

* Revert "[TMP] Show packaging version"

This reverts commit 910b6bb.

* Add `-U` flag

* Set packaging version as >=23.2

* Revert the changes on pip install

* Set packaging version as >=23.2 in requirements.txt

* Revert "Set packaging version as >=23.2"

This reverts commit 8aa77c8.

* Fix hook name

* Revert "Set packaging version as >=23.2 in requirements.txt"

This reverts commit fbd605c.

* Revert "Revert the changes on pip install"

This reverts commit 81ff38a.

* Add comments

* Revert "[TMP] Change the branch of action files"

This reverts commit 0d6aa48.

* Revert the trigger of .github/workflows/deploy-spaces.yml

* Remove unused `node_auth_token` and `npm_token` inputs from the `install-all-deps` action

* [TMP] Trigger CI based on this PR

* Remove packging installation

* Revert "Remove packging installation"

This reverts commit 4a4f18d.

* Revert "[TMP] Trigger CI based on this PR"

This reverts commit 6cea830.

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
* Add code

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* add msw setup and initialisation tests

* add changeset

* add walk_and_store_blobs improvements and add tests

* add changeset

* api_info tests

* add direct space URL link tests

* fix tests

* add view_api tests

* add post_message test

* tweak

* add spaces tests

* jwt and protocol tests

* add post_data tests

* test tweaks

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
…eeded (#8174)

* Remove hatch installation in js/app/package.json which is no longer needed

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* Update test-functional.yml

* Update test-functional.yml

* tweaks

---------

Co-authored-by: pngwn <hello@pngwn.io>
…8179)

* rework upload to be a class method + pass client into each component

* add changeset

* Update client/js/src/utils/upload_files.ts

* fix storybook

* review comments

* Apply suggestions from code review

Co-authored-by: Hannah <hannahblair@users.noreply.github.com>

* format

* ts fix

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
* chore(deps): update pnpm to v9

* update workflow

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: pngwn <hello@pngwn.io>
* workspace

* add changeset

* remove circular import from preview

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* get error message

* Support multiple clients

* add changeset

* add changeset

* add changeset

* Display in UI

* console.error the python traceback

* lint

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* convert sse calls in client from async to sync

* add changeset

* more sync

* lint

* more sync

* fix threadpool

* fix timeouts

* reuse executor

* lint

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* run python reload only if python file changed

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
…_thread in blocks.py (#8158)

* fix: handling SIGINT, single block_thread and fix popen

* Use pass

---------

Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
* add msw setup and initialisation tests

* add changeset

* add eventsource polyfill for node and browser envs

* add changeset

* add changeset

* config tweak

* types

* update eventsource usage

* add changeset

* add walk_and_store_blobs improvements and add tests

* add changeset

* api_info tests

* add direct space URL link tests

* fix tests

* add view_api tests

* add post_message test

* tweak

* add spaces tests

* jwt and protocol tests

* add post_data tests

* test tweaks

* dynamically import eventsource

* revet eventsource imports

* add node test

* lockfile

* add client test in root pkg file

* lcokfile

* remove eventsource from js/app

* add changeset

* remove ts ignore

* move eventsource polyfill to eventsource factory

* add changeset

* tweak

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* add msw setup and initialisation tests

* add changeset

* add eventsource polyfill for node and browser envs

* add changeset

* add changeset

* config tweak

* types

* update eventsource usage

* add changeset

* add walk_and_store_blobs improvements and add tests

* add changeset

* api_info tests

* add direct space URL link tests

* fix tests

* add view_api tests

* add post_message test

* tweak

* add spaces tests

* jwt and protocol tests

* add post_data tests

* test tweaks

* dynamically import eventsource

* revet eventsource imports

* add jwt param to sse requests

* add stream test

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* Add code

* add changeset

* Update fuzzy-mirrors-scream.md

* Update fuzzy-mirrors-scream.md

* Fix tests

* Update .changeset/fuzzy-mirrors-scream.md

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Fix code

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
* Analytics refactor

* add changeset

* add changeset

* Fix wasm?

* Fix python tests'

* Revert changes chrome

* use util function

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
… is not available on Pyodide yet (#8204)

* Specify the fastapi version on Lite to avoid ujson installation which is not available on Pyodide yet

* add changeset

* Refactoring

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* Set the show_api flag on Lite

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
…nes on Lite (#8052)

* Extend Interface.from_pipeline() to support Transformers.js.py pipelines on Lite (wip: only object-detection in this commit)

* add changeset

* Add image-classification and image-segmentation

* Add zero-shot-image-classification and zero-shot-object-detection

* Add document-question-answering

* Add feature-extraction and fill-mask

* Add question-answering and summarization

* Fix an error message

* Add text2text-generation, text-classification, and text-generation

* Add translation andtranslation_xx_to_yy

* Add zero-shot-classification

* Add postprocess_takes_inputs to control the args passed to the postprocess function of each pipeline

* Add topk option to image-classification

* format_backend

* Add audio-classification, automatic-speech-recognition, and zero-shot-audio-classification

* Add image-to-text

* Add token-classification (with JSON component as an output. Is it correct?)

* Ignore import type failure of transformers_js_py

* Add image-feature-extraction

* Add image-to-image

* Add text-to-audio

* Add depth-estimation

* Remove `render=False`

* Reorder the if-blocks following the Transformers.js doc

* Update gradio/pipelines_utils.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Update gradio/pipelines_utils.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Fix feature-extraction demo

* Fix demo title

* Add guides/08_gradio-clients-and-lite/gradio-lite-and-transformers-js.md without contents

* Rename guides/08_gradio-clients-and-lite/*.md to fix the order

* Use pipeline.model.config._name_or_path for the demo title instead of pipeline.model.config.model_type

* Fix normal Interface.from_pipeline to use pipeline.model.config.name_or_path as the demo title

* Write an article about Gradio-Lite and Transformers.js

* Update the doc

* tweaks

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
hannahblair and others added 10 commits May 6, 2024 10:01
* remove redundant event source logic

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
* Add connect_heartbeat field

* fix types

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
@dawoodkhan82 dawoodkhan82 marked this pull request as ready for review May 13, 2024 15:32
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

🔥 PR @dawoodkhan82 ! Made some suggestions to simplify the api in the backend

demo/chatbot_multimodal/run.py Outdated Show resolved Hide resolved
gradio/components/chatbot.py Show resolved Hide resolved
gradio/components/chatbot.py Show resolved Hide resolved
gradio/components/chatbot.py Outdated Show resolved Hide resolved
gradio/components/chatbot.py Outdated Show resolved Hide resolved
gradio/components/chatbot.py Outdated Show resolved Hide resolved
["Video", gr.Video(value="files/world.mp4", render=False)],
["Audio", gr.Audio(value="files/cantina.wav", render=False)],
["Plot", gr.Plot(value=fig, render=False)],
["Gallery", gr.Gallery(value=["files/lion.jpg", "files/cheetah.jpg", "files/zebra.jpg"], render=False)]],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@freddyaboulton Any suggestions on how to simplify this so render=False is not necessary? I tried passing it as a constructor arg during postprocessing, but the component would still render.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you call unrender for each component in the initial value in the chatbot init?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering if it would work.

@andreped
Copy link
Contributor

@dawoodkhan82 Would be neat if there was added support for gradio.Dataframe, gradio.Code, and gradio.Button as well, as our application needs it :] As a minimum, gradio.Dataframe would be quite neat.

Could be done in a separate PR I suppose. Just throwing it out there, as you are already adding support for five of the most commonly used ones.

@dawoodkhan82
Copy link
Collaborator Author

@andreped For sure, dataframe is already on the roadmap. Will look into adding additional components in a future PR.

@dawoodkhan82 dawoodkhan82 requested a review from pngwn May 16, 2024 18:31
@abidlabs abidlabs requested a review from aliabid94 May 16, 2024 18:37
@aliabid94
Copy link
Collaborator

Sorry should've commented earlier, but this seems a lot of custom code for each component. We should have a general approach that works for all components, rather than having to support each component one by one. We should also only import components "dynamically" if needed, rather than making chatbot have every other type of component as a dependency.
Also think visually, Component outputs should not be in a bubble, but stand alone in their usual Block.
Happy to sync on this to design a solution.

@dawoodkhan82
Copy link
Collaborator Author

Ok worked on refactoring the PR to generalize for all components, but reached some areas where I still can't get rid of some custom code. cc @aliabid94 lmk if you want to sync on a solution to see if its possible without having to change component code itself.

else:
raise ValueError(
f"Invalid component for Chatbot component: {chat_message.component}"
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@aliabid94 here we still need some custom code for some components

/>
{:else if message !== null && message.file?.url !== null}
{:else if message !== null && "component" in message}
{#if message.component == "gallery"}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Similar thing here, accessing the value can be different per component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet