-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Gradio Web Server for Multimodal Models #2960
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 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9eba123
Move <image> tokens to openai_server
BabyChouSr 10f63a2
Add gradio vision block and have workers register themselves as multi…
BabyChouSr 606f7f7
Add gradio web server demo
BabyChouSr eafd1aa
Address comments and test using llava v1.6
BabyChouSr 6b17f34
Merge branch 'main' into gradio-multi
BabyChouSr 19375f7
format
BabyChouSr f976725
Add hashing images and storing them in server
BabyChouSr cd019e6
Fix
BabyChouSr 9695257
Merge remote-tracking branch 'origin/main' into gradio-multi
merrymercy 77dc1f3
update gradio version
merrymercy 6a4d1dd
update
merrymercy d0d319f
format
merrymercy 8997ad1
fix pydantic
merrymercy 4e3132c
update
merrymercy 93a1e84
update
merrymercy 7bb8f11
format
merrymercy 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,187 @@ | ||
| """ | ||
| The gradio demo server for chatting with a single model. | ||
| """ | ||
BabyChouSr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import os | ||
|
|
||
| import gradio as gr | ||
|
|
||
| from fastchat.serve.gradio_web_server import ( | ||
| upvote_last_response, | ||
| downvote_last_response, | ||
| flag_last_response, | ||
| get_model_description_md, | ||
| acknowledgment_md, | ||
| bot_response, | ||
| add_text, | ||
| clear_history, | ||
| regenerate, | ||
| ) | ||
| from fastchat.utils import ( | ||
| build_logger, | ||
| ) | ||
|
|
||
| logger = build_logger("gradio_web_server_multi", "gradio_web_server_multi.log") | ||
| enable_moderation = False | ||
|
|
||
|
|
||
| def build_single_vision_language_model_ui(models, add_promotion_links=False): | ||
| promotion = ( | ||
| """ | ||
| - | [GitHub](https://github.com/lm-sys/FastChat) | [Dataset](https://github.com/lm-sys/FastChat/blob/main/docs/dataset_release.md) | [Twitter](https://twitter.com/lmsysorg) | [Discord](https://discord.gg/HSWAKCrnFx) | | ||
| - Introducing Llama 2: The Next Generation Open Source Large Language Model. [[Website]](https://ai.meta.com/llama/) | ||
| - Vicuna: An Open-Source Chatbot Impressing GPT-4 with 90% ChatGPT Quality. [[Blog]](https://lmsys.org/blog/2023-03-30-vicuna/) | ||
BabyChouSr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| if add_promotion_links | ||
| else "" | ||
| ) | ||
|
|
||
| notice_markdown = f""" | ||
| # 🏔️ Chat with Open Large Vision-Language Models | ||
| {promotion} | ||
| ### Choose a model to chat with | ||
| """ | ||
|
|
||
| state = gr.State() | ||
|
|
||
| with gr.Box(): | ||
| with gr.Row(elem_id="model_selector_row"): | ||
| model_selector = gr.Dropdown( | ||
| choices=models, | ||
| value=models[0] if len(models) > 0 else "", | ||
| interactive=True, | ||
| show_label=False, | ||
| container=False, | ||
| ) | ||
|
|
||
| with gr.Accordion( | ||
| "🔍 Expand to see 20+ model descriptions", | ||
| open=False, | ||
| elem_id="model_description_accordion", | ||
| ): | ||
| model_description_md = get_model_description_md(models) | ||
| gr.Markdown(model_description_md, elem_id="model_description_markdown") | ||
|
|
||
| with gr.Row(): | ||
| with gr.Column(scale=3): | ||
| textbox = gr.Textbox( | ||
| show_label=False, | ||
| placeholder="Enter your prompt here and press ENTER", | ||
| container=False, | ||
| render=False, | ||
| elem_id="input_box", | ||
| ) | ||
| imagebox = gr.Image(type="pil") | ||
|
|
||
| cur_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
|
||
| with gr.Accordion("Parameters", open=False) as parameter_row: | ||
| temperature = gr.Slider( | ||
| minimum=0.0, | ||
| maximum=1.0, | ||
| value=0.2, | ||
| step=0.1, | ||
| interactive=True, | ||
| label="Temperature", | ||
| ) | ||
| top_p = gr.Slider( | ||
| minimum=0.0, | ||
| maximum=1.0, | ||
| value=0.7, | ||
| step=0.1, | ||
| interactive=True, | ||
| label="Top P", | ||
| ) | ||
| max_output_tokens = gr.Slider( | ||
| minimum=0, | ||
| maximum=1024, | ||
| value=512, | ||
| step=64, | ||
| interactive=True, | ||
| label="Max output tokens", | ||
| ) | ||
|
|
||
| gr.Examples( | ||
| examples=[ | ||
| [ | ||
| f"{cur_dir}/example_images/city.jpeg", | ||
| "Explain this photo.", | ||
| ], | ||
| [ | ||
| f"{cur_dir}/example_images/fridge.jpeg", | ||
| "What is in this fridge?", | ||
| ], | ||
| ], | ||
| inputs=[imagebox, textbox], | ||
| ) | ||
|
|
||
| with gr.Column(scale=8): | ||
| chatbot = gr.Chatbot( | ||
| elem_id="chatbot", label="Scroll down and start chatting", height=550 | ||
| ) | ||
|
|
||
| with gr.Row(): | ||
| with gr.Column(scale=8): | ||
| textbox.render() | ||
| with gr.Column(scale=1, min_width=50): | ||
| send_btn = gr.Button(value="Send", variant="primary") | ||
| with gr.Row(elem_id="buttons"): | ||
| upvote_btn = gr.Button(value="👍 Upvote", interactive=False) | ||
| downvote_btn = gr.Button(value="👎 Downvote", interactive=False) | ||
| flag_btn = gr.Button(value="⚠️ Flag", interactive=False) | ||
| regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False) | ||
| clear_btn = gr.Button(value="🗑️ Clear", interactive=False) | ||
|
|
||
| if add_promotion_links: | ||
| gr.Markdown(acknowledgment_md) | ||
|
|
||
| # Register listeners | ||
| btn_list = [upvote_btn, downvote_btn, flag_btn, regenerate_btn, clear_btn] | ||
| upvote_btn.click( | ||
| upvote_last_response, | ||
| [state, model_selector], | ||
| [textbox, upvote_btn, downvote_btn, flag_btn], | ||
| ) | ||
| downvote_btn.click( | ||
| downvote_last_response, | ||
| [state, model_selector], | ||
| [textbox, upvote_btn, downvote_btn, flag_btn], | ||
| ) | ||
| flag_btn.click( | ||
| flag_last_response, | ||
| [state, model_selector], | ||
| [textbox, upvote_btn, downvote_btn, flag_btn], | ||
| ) | ||
| regenerate_btn.click( | ||
| regenerate, state, [state, chatbot, textbox, imagebox] + btn_list | ||
| ).then( | ||
| bot_response, | ||
| [state, temperature, top_p, max_output_tokens], | ||
| [state, chatbot] + btn_list, | ||
| ) | ||
| clear_btn.click(clear_history, None, [state, chatbot, textbox, imagebox] + btn_list) | ||
|
|
||
| model_selector.change( | ||
| clear_history, None, [state, chatbot, textbox, imagebox] + btn_list | ||
| ) | ||
|
|
||
| textbox.submit( | ||
| add_text, | ||
| [state, model_selector, textbox, imagebox], | ||
| [state, chatbot, textbox, imagebox] + btn_list, | ||
| ).then( | ||
| bot_response, | ||
| [state, temperature, top_p, max_output_tokens], | ||
| [state, chatbot] + btn_list, | ||
| ) | ||
| send_btn.click( | ||
| add_text, | ||
| [state, model_selector, textbox, imagebox], | ||
| [state, chatbot, textbox, imagebox] + btn_list, | ||
| ).then( | ||
| bot_response, | ||
| [state, temperature, top_p, max_output_tokens], | ||
| [state, chatbot] + btn_list, | ||
| ) | ||
|
|
||
| return [state, model_selector] | ||
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.