Skip to content

Commit

Permalink
rebranding
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-diver committed Apr 20, 2023
1 parent 270280d commit 39a10c4
Show file tree
Hide file tree
Showing 27 changed files with 513 additions and 1,051 deletions.
166 changes: 55 additions & 111 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,147 +1,91 @@
import time
import gradio as gr

import global_vars

from args import parse_args
from miscs.strings import TITLE, ABSTRACT, BOTTOM_LINE
from miscs.strings import DEFAULT_EXAMPLES
from miscs.styles import PARENT_BLOCK_CSS
from miscs.strings import SPECIAL_STRS
from utils import get_chat_interface, get_chat_manager

from utils import get_chat_interface
from miscs.styles import PARENT_BLOCK_CSS
from miscs.strings import BOTTOM_LINE

def reset_textbox():
return gr.Textbox.update(value='')

def reset_everything(
context_txtbox,
instruction_txtbox,
state_chatbot):

state_chatbot = []

# [chatbot, chat_state, inspector, instruction_txtbox],
def reset_everything():
return (
state_chatbot,
state_chatbot,
gr.Textbox.update(value=''),
gr.Textbox.update(value=''),
[],
{"ppmanager": get_chat_manager(global_vars.model_type)},
"",
"",
)

def toggle_inspector(view_selector):
if view_selector == "with context inspector":
return gr.update(visible=True)
else:
return gr.update(visible=False)

def run(args):
global_vars.initialize_globals(args)
batch_enabled = global_vars.batch_enabled
chat_interface = get_chat_interface(global_vars.model_type, batch_enabled)

with gr.Blocks(css=PARENT_BLOCK_CSS, theme='ParityError/Anime') as demo:
state_chatbot = gr.State([])

with gr.Column(elem_id='col_container'):
gr.Markdown(f"## {TITLE}\n\n\n{ABSTRACT}")

with gr.Accordion("Context Setting", open=False):
context_txtbox = gr.Textbox(placeholder="Surrounding information to AI", label="Context")
hidden_txtbox = gr.Textbox(placeholder="", label="Order", visible=False)
chat_interface = get_chat_interface(global_vars.model_type)

chatbot = gr.Chatbot(elem_id='chatbot', label=global_vars.model_type)
instruction_txtbox = gr.Textbox(placeholder="What do you want to say to AI?", label="Instruction")
with gr.Blocks(css=PARENT_BLOCK_CSS, theme='ParityError/Anime') as demo:
chat_state = gr.State({
"ppmanager": get_chat_manager(global_vars.model_type)
})

with gr.Column(elem_id='col-container'):
view_selector = gr.Radio(
["with context inspector", "without context inspector"],
value="without context inspector",
label="View Selector",
info="How do you like to use this application?",
visible=not args.chat_only_mode
)

with gr.Row():
cancel_btn = gr.Button(value="Cancel")
reset_btn = gr.Button(value="Reset")
with gr.Column(elem_id='chatbot-wrapper'):
chatbot = gr.Chatbot(elem_id='chatbot', label=global_vars.model_type)
instruction_txtbox = gr.Textbox(placeholder="What do you want to say to AI?", label="Instruction")

with gr.Accordion("Helper Buttons", open=False):
gr.Markdown(f"`Continue` lets AI to complete the previous incomplete answers. `Summarize` lets AI to summarize the conversations so far.")
continue_txtbox = gr.Textbox(value=SPECIAL_STRS["continue"], visible=False)
summrize_txtbox = gr.Textbox(value=SPECIAL_STRS["summarize"], visible=False)
with gr.Row():
cancel_btn = gr.Button(value="Cancel")
reset_btn = gr.Button(value="Reset")

with gr.Column(visible=False) as context_inspector_section:
gr.Markdown("#### What model actually sees")
inspector = gr.Textbox(label="", lines=28, max_lines=28, interactive=False)

with gr.Accordion("Acknowledgements", open=False, visible=not args.chat_only_mode):
gr.Markdown(f"{BOTTOM_LINE}")

view_selector.change(
toggle_inspector,
view_selector,
context_inspector_section
)

continue_btn = gr.Button(value="Continue")
summarize_btn = gr.Button(value="Summarize")

gr.Markdown("#### Examples")
for _, (category, examples) in enumerate(DEFAULT_EXAMPLES.items()):
with gr.Accordion(category, open=False):
if category == "Identity":
for item in examples:
with gr.Accordion(item["title"], open=False):
gr.Examples(
examples=item["examples"],
inputs=[
hidden_txtbox, context_txtbox, instruction_txtbox
],
label=None
)
else:
for item in examples:
with gr.Accordion(item["title"], open=False):
gr.Examples(
examples=item["examples"],
inputs=[
hidden_txtbox, instruction_txtbox
],
label=None
)

gr.Markdown(f"{BOTTOM_LINE}")

send_event = instruction_txtbox.submit(
chat_interface,
[context_txtbox, instruction_txtbox, state_chatbot],
[state_chatbot, chatbot, context_txtbox],
batch=batch_enabled,
max_batch_size=args.batch_size,
)
reset_event = instruction_txtbox.submit(
reset_textbox,
[],
[instruction_txtbox],
)

continue_event = continue_btn.click(
chat_interface,
[context_txtbox, continue_txtbox, state_chatbot],
[state_chatbot, chatbot, context_txtbox],
batch=batch_enabled,
max_batch_size=args.batch_size,
)
reset_continue_event = continue_btn.click(
reset_textbox,
[],
[instruction_txtbox],
)

summarize_event = summarize_btn.click(
chat_interface,
[context_txtbox, summrize_txtbox, state_chatbot],
[state_chatbot, chatbot, context_txtbox],
batch=batch_enabled,
max_batch_size=args.batch_size,
)
summarize_reset_event = summarize_btn.click(
reset_textbox,
[],
[instruction_txtbox],
[instruction_txtbox, chat_state],
[instruction_txtbox, chatbot, inspector, chat_state],
)

cancel_btn.click(
None, None, None,
cancels=[
send_event, continue_event, summarize_event
]
cancels=[send_event]
)

reset_btn.click(
reset_everything,
[context_txtbox, instruction_txtbox, state_chatbot],
[state_chatbot, chatbot, context_txtbox, instruction_txtbox],
cancels=[
send_event, continue_event, summarize_event
]
None,
[chatbot, chat_state, inspector, instruction_txtbox],
cancels=[send_event]
)

demo.queue(
concurrency_count=2,
max_size=100,
api_open=args.api_open
).launch(
max_threads=10,
share=args.share,
Expand Down
48 changes: 27 additions & 21 deletions args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ def parse_args():
parser = argparse.ArgumentParser(
description="Gradio Application for Alpaca-LoRA as a chatbot service"
)
# Dataset related.
parser.add_argument(
"--base_url",
"--base-url",
help="Hugging Face Hub URL",
default="decapoda-research/llama-7b-hf",
# default="decapoda-research/llama-7b-hf",
default="stabilityai/stablelm-tuned-alpha-7b",
type=str,
)
parser.add_argument(
"--ft_ckpt_url",
"--ft-ckpt-url",
help="Hugging Face Hub URL",
default="tloen/alpaca-lora-7b",
type=str,
Expand All @@ -24,48 +24,54 @@ def parse_args():
type=int,
)
parser.add_argument(
"--batch_size",
"--batch-size",
help="Number of requests to handle at the same time",
default=1,
type=int
)
parser.add_argument(
"--api_open",
help="Open as API",
action='store_true'
)
parser.add_argument(
"--share",
help="Create and share temporary endpoint (useful in Colab env)",
action='store_true'
)
parser.add_argument(
"--gen_config_path",
help="path to GenerationConfig file used in batch mode",
"--gen-config-path",
help="path to GenerationConfig file",
default="configs/gen_config_default.yaml",
type=str
)
parser.add_argument(
"--gen_config_summarization_path",
"--gen-config-summarization-path",
help="path to GenerationConfig file used in context summarization",
default="configs/gen_config_summarization.yaml",
type=str
)
# parser.add_argument(
# "--get-constraints-config-path",
# help="path to ConstraintsConfig file used to constraint user inputs",
# default="configs/constraints_config.yaml",
# type=str
# )
parser.add_argument(
"--get_constraints_config_path",
help="path to ConstraintsConfig file used to constraint user inputs",
default="configs/constraints_config.yaml",
type=str
)
parser.add_argument(
"--multi_gpu",
"--multi-gpu",
help="Enable multi gpu mode. This will force not to use Int8 but float16, so you need to check if your system has enough GPU memory",
action='store_true'
)
parser.add_argument(
"--force_download_ckpt",
"--force-download_ckpt",
help="Force to download ckpt instead of using cached one",
action="store_true"
)
parser.add_argument(
"--chat-only-mode",
help="Only show chatting window. Otherwise, other components will be appeared for more sophisticated control",
action="store_true"
)
parser.add_argument(
"--batch_size",
help="Number of requests to handle at the same time",
default=1,
type=int
)

return parser.parse_args()
Binary file added assets/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 39a10c4

Please sign in to comment.