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

[Assistants] Use textToImage task for avatar generation #662

Merged
merged 11 commits into from
Jan 15, 2024

Conversation

nsarrazin
Copy link
Collaborator

This PR adds a togglable feature for generating the assistants avatars using a customizable text to image model.

@nsarrazin nsarrazin added enhancement New feature or request front This issue is related to the front-end of the app. back This issue is related to the Svelte backend or the DB labels Dec 26, 2023
@nsarrazin
Copy link
Collaborator Author

Need to put a front-facing checkbox for the user to use this feature or not when creating an avatar, but as a poc it works quite well. for huggingchat in prod we may need to pin a model for this if possible, to reduce generation latency

@nsarrazin
Copy link
Collaborator Author

I added a user control in the assistant creation form.
image

There's also a 30s timeout on the image generation.

@nsarrazin nsarrazin requested a review from gary149 December 27, 2023 13:02
@nsarrazin nsarrazin changed the title Use textToImage task for assistants avatar generation [Assistants] Use textToImage task for avatar generation Dec 27, 2023
@nsarrazin nsarrazin mentioned this pull request Jan 9, 2024
@mishig25
Copy link
Collaborator

mishig25 commented Jan 12, 2024

I'd like to review it soon. Could you resolve the conflicts in the meantime?

@nsarrazin
Copy link
Collaborator Author

Should be good @mishig25 !

@mishig25
Copy link
Collaborator

mishig25 commented Jan 12, 2024

From UX-wise, if you click "generate avatar", you shouldn't be able to select local img (i.e, click "click to upload", it should be disabled). Otherwise, it is confusing, which image will be used

Screen.Recording.2024-01-12.at.5.46.41.PM.mov

ENABLE_ASSISTANTS=false #set to true to enable assistants feature
ASSISTANTS_GENERATE_AVATAR=true #requires an hf token, uses the model description and name to generate an avatar using a text to image model
TEXT_TO_IMAGE_MODEL="runwayml/stable-diffusion-v1-5"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: but we can use newer models like https://huggingface.co/latent-consistency/lcm-lora-ssd-1b (assuming that they are hosted on inference API) that produce higher quality images faster

  1. It is higher quality because, it is based on SD XL
  2. It produces images faster, because it is smaller model (ssd) & uses fewer sampling (lcm-lora)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah that's fair! I picked sd1.5 over sdxl because I assumed it'd be faster but if we have faster models available by all mean let's change it 😁

I think we should prio speed>image quality for this feature, most of the time this will be seen as only a small thumbnail, so if you have good model recommendations, feel free!

Copy link
Collaborator

Choose a reason for hiding this comment

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

for example, https://huggingface.co/latent-consistency/lcm-lora-sdv1-5 would be faster than runway/sd-1.5. https://huggingface.co/latent-consistency/lcm-lora-sdxl might still be faster than runway/sd-1.5. Maybe @patil-suraj @sayakpaul can confirm?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Since it's SDXL, it will not be SD speed. You can try out Segmind's SSD-1B.

Copy link
Collaborator

@mishig25 mishig25 Jan 12, 2024

Choose a reason for hiding this comment

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

So https://huggingface.co/latent-consistency/lcm-lora-ssd-1b would be the best, in terms of speed/quality tradeoff?

Copy link
Member

Choose a reason for hiding this comment

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

I would say so. But, would also consider playing SD Turbo.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the license of SD Turbo ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried latent-consistency/lcm-lora-ssd-1bz but it doesn't seem to load, I think it would need to be pinned in the API on our side if we go for it, just a note not necessarily a blocker 😁

@nsarrazin
Copy link
Collaborator Author

From UX-wise, if you click "generate avatar", you shouldn't be able to select local img (i.e, click "click to upload", it should be disabled). Otherwise, it is confusing, which image will be used
Screen.Recording.2024-01-12.at.5.46.41.PM.mov

The intent was that if an image is uploaded, it takes precedence over the checkbox (the checkbox disappears and the image preview is shown instead) but if you think it's clearer to also disable the upload button when the checkbox is checked then I can add that for sure. Do you think it's better if the button is disabled or completely hidden ?

@mishig25
Copy link
Collaborator

mishig25 commented Jan 15, 2024

Do you think it's better if the button is disabled or completely hidden ?

disabled

@nsarrazin
Copy link
Collaborator Author

Do you think it's better if the button is disabled or completely hidden ?

disabled

done!

Copy link
Collaborator

@mishig25 mishig25 left a comment

Choose a reason for hiding this comment

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

lgtm from my side!

@nsarrazin
Copy link
Collaborator Author

There's a feature flag in front of it so I think we can merge this back into the assistants PR and then enable the flag or not in the prod config if we decide to go for it

@nsarrazin nsarrazin merged commit f6c61eb into feature/assistants Jan 15, 2024
3 checks passed
@nsarrazin nsarrazin deleted the feature/use_sd_for_avatar branch January 15, 2024 09:42
nsarrazin added a commit that referenced this pull request Jan 24, 2024
* First push on assistants

* push fixes

* fix add assistant

* Sign up works

* lint

* mobile layout fixes

* design fixes

* Merge branch 'main' into feature/assistants

* fix copy button

* add error feedback

* hide duplicate feature

* remove wrong comments

* add autoredirect if assistant is missing

* latest changes:
- add edit feature
- hash assistant avatar
- get rid of ugly line
- check for non existent avatar
- make a better looking upload icon

* Update src/routes/conversation/+server.ts

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

* reused type more cleanly

* fix type in shared conversation

* fixed feature

* fix: share conv with an assistant

* delete assistant avatars in db when deleting avatar

* affordance on avatar upload

* improve assistant conv start on mobile

* settings modal fly in

* better mobile intro

* mobile padding

* link affordance

* Make assistants disabled by default, but enabled in huggingchat

* lint

* Fix bottom model name

* ui tweaks

* Initial work on chat thumbnails

* fix build

* Get rid of deps

* Update src/routes/settings/assistants/[assistantId]/avatar/+server.ts

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

* add comment to app_base

* Use event modifiers

* Use CSS uppercase instead everywhere

* Update src/lib/components/NavMenu.svelte

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

* Update src/routes/+layout.server.ts

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

* Clearer error message for avatar size check

* one less op on flag check

* revert back preventDefault change in LoginModal

* Update src/routes/settings/+layout.svelte

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

* Update src/routes/+layout.server.ts

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

* Update src/routes/+layout.server.ts

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

* Added app logo in corner of thumbnail and clamped description length

* improved thumbnails

* Remove warnings

* Reuse Assisntants settings component (#678)

* Update Assisntants settings

* format

* [Assistants] Use textToImage task for avatar generation (#662)

* Generate assistants avatar using stablediffusion

* wording

* Update +page.server.ts

Co-authored-by: Michael Fried <[email protected]>

* Add timeout & controls to avatar generation

* Add controls for avatar generation in .env

* Update src/routes/+layout.server.ts

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

* Update src/lib/components/AssistantSettings.svelte

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

* Fix avatar gen feature flag

* Can only upload avatar if generate is unchecked

---------

Co-authored-by: Michael Fried <[email protected]>
Co-authored-by: Mishig <[email protected]>

* layout

* small fixes

* hint

* Show feature if login is not required

* lint

* Only show creator name if it's defined

* tweaks

* thumbnail update

* thumbnail font-size

* Always display model at the bottom

* Bottom links now go to settings

* fix lint

* silent release

* fix bg on share link

* [Assistant] Delete avatar button instead of reset (#725)

* Add rate-limited image generating endpoint

* Add generate avatar button

* add little padding for firefox focus ring

* format

* fix upload image bug

* Fix uploads, replace reset by delete

* left-align buttons

* rm avatar generation feature

* final changes to delete feature

* sys prompt min height

* padding

* Add object-cover everywhere

---------

Co-authored-by: Victor Mustar <[email protected]>

---------

Co-authored-by: Mishig <[email protected]>
Co-authored-by: Victor Mustar <[email protected]>
Co-authored-by: Michael Fried <[email protected]>
ice91 pushed a commit to ice91/chat-ui that referenced this pull request Oct 30, 2024
* First push on assistants

* push fixes

* fix add assistant

* Sign up works

* lint

* mobile layout fixes

* design fixes

* Merge branch 'main' into feature/assistants

* fix copy button

* add error feedback

* hide duplicate feature

* remove wrong comments

* add autoredirect if assistant is missing

* latest changes:
- add edit feature
- hash assistant avatar
- get rid of ugly line
- check for non existent avatar
- make a better looking upload icon

* Update src/routes/conversation/+server.ts

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

* reused type more cleanly

* fix type in shared conversation

* fixed feature

* fix: share conv with an assistant

* delete assistant avatars in db when deleting avatar

* affordance on avatar upload

* improve assistant conv start on mobile

* settings modal fly in

* better mobile intro

* mobile padding

* link affordance

* Make assistants disabled by default, but enabled in huggingchat

* lint

* Fix bottom model name

* ui tweaks

* Initial work on chat thumbnails

* fix build

* Get rid of deps

* Update src/routes/settings/assistants/[assistantId]/avatar/+server.ts

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

* add comment to app_base

* Use event modifiers

* Use CSS uppercase instead everywhere

* Update src/lib/components/NavMenu.svelte

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

* Update src/routes/+layout.server.ts

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

* Clearer error message for avatar size check

* one less op on flag check

* revert back preventDefault change in LoginModal

* Update src/routes/settings/+layout.svelte

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

* Update src/routes/+layout.server.ts

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

* Update src/routes/+layout.server.ts

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

* Added app logo in corner of thumbnail and clamped description length

* improved thumbnails

* Remove warnings

* Reuse Assisntants settings component (huggingface#678)

* Update Assisntants settings

* format

* [Assistants] Use textToImage task for avatar generation (huggingface#662)

* Generate assistants avatar using stablediffusion

* wording

* Update +page.server.ts

Co-authored-by: Michael Fried <[email protected]>

* Add timeout & controls to avatar generation

* Add controls for avatar generation in .env

* Update src/routes/+layout.server.ts

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

* Update src/lib/components/AssistantSettings.svelte

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

* Fix avatar gen feature flag

* Can only upload avatar if generate is unchecked

---------

Co-authored-by: Michael Fried <[email protected]>
Co-authored-by: Mishig <[email protected]>

* layout

* small fixes

* hint

* Show feature if login is not required

* lint

* Only show creator name if it's defined

* tweaks

* thumbnail update

* thumbnail font-size

* Always display model at the bottom

* Bottom links now go to settings

* fix lint

* silent release

* fix bg on share link

* [Assistant] Delete avatar button instead of reset (huggingface#725)

* Add rate-limited image generating endpoint

* Add generate avatar button

* add little padding for firefox focus ring

* format

* fix upload image bug

* Fix uploads, replace reset by delete

* left-align buttons

* rm avatar generation feature

* final changes to delete feature

* sys prompt min height

* padding

* Add object-cover everywhere

---------

Co-authored-by: Victor Mustar <[email protected]>

---------

Co-authored-by: Mishig <[email protected]>
Co-authored-by: Victor Mustar <[email protected]>
Co-authored-by: Michael Fried <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back This issue is related to the Svelte backend or the DB enhancement New feature or request front This issue is related to the front-end of the app.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants