Reorganize the layout

This commit is contained in:
oobabooga 2023-01-06 22:05:37 -03:00
parent b53b658320
commit 3d6a3aac73

View file

@ -83,13 +83,13 @@ def generate_reply(question, temperature, max_length, inference_settings, select
if model_name.lower().startswith('galactica'): if model_name.lower().startswith('galactica'):
return reply, reply return reply, reply
else: else:
return reply, '' return reply, 'Only applicable for galactica models.'
# Choosing the default model # Choosing the default model
if args.model is not None: if args.model is not None:
model_name = args.model model_name = args.model
else: else:
if len(available_models == 0): if len(available_models) == 0:
print("No models are available! Please download at least one.") print("No models are available! Please download at least one.")
exit(0) exit(0)
elif len(available_models) == 1: elif len(available_models) == 1:
@ -117,31 +117,44 @@ if args.notebook:
""" """
) )
textbox = gr.Textbox(value=default_text, lines=23) with gr.Tab('Raw'):
temp_slider = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Temperature', value=0.7) textbox = gr.Textbox(value=default_text, lines=23)
length_slider = gr.Slider(minimum=1, maximum=2000, step=1, label='max_length', value=200) with gr.Tab('Markdown'):
preset_menu = gr.Dropdown(choices=list(map(lambda x : x.split('/')[-1].split('.')[0], glob.glob("presets/*.txt"))), value="Default", label='Preset') markdown = gr.Markdown()
model_menu = gr.Dropdown(choices=available_models, value=model_name, label='Model')
btn = gr.Button("Generate") btn = gr.Button("Generate")
markdown = gr.Markdown()
with gr.Row():
with gr.Column():
temp_slider = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Temperature', value=0.7)
length_slider = gr.Slider(minimum=1, maximum=2000, step=1, label='max_length', value=200)
with gr.Column():
preset_menu = gr.Dropdown(choices=list(map(lambda x : x.split('/')[-1].split('.')[0], glob.glob("presets/*.txt"))), value="Default", label='Preset')
model_menu = gr.Dropdown(choices=available_models, value=model_name, label='Model')
btn.click(generate_reply, [textbox, temp_slider, length_slider, preset_menu, model_menu], [textbox, markdown], show_progress=False) btn.click(generate_reply, [textbox, temp_slider, length_slider, preset_menu, model_menu], [textbox, markdown], show_progress=False)
else: else:
interface = gr.Interface( with gr.Blocks() as interface:
generate_reply, gr.Markdown(
inputs=[ f"""
gr.Textbox(value=default_text, lines=15), # Text generation lab
gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Temperature', value=0.7), Generate text using Large Language Models.
gr.Slider(minimum=1, maximum=2000, step=1, label='max_length', value=200), """
gr.Dropdown(choices=list(map(lambda x : x.split('/')[-1].split('.')[0], glob.glob("presets/*.txt"))), value="Default", label='Preset'), )
gr.Dropdown(choices=available_models, value=model_name, label='Model'),
], with gr.Row():
outputs=[ with gr.Column():
gr.Textbox(placeholder="", lines=15), textbox = gr.Textbox(value=default_text, lines=15, label='Input')
gr.Markdown() temp_slider = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Temperature', value=0.7)
], length_slider = gr.Slider(minimum=1, maximum=2000, step=1, label='max_length', value=200)
title="Text generation lab", preset_menu = gr.Dropdown(choices=list(map(lambda x : x.split('/')[-1].split('.')[0], glob.glob("presets/*.txt"))), value="Default", label='Preset')
description=f"Generate text using Large Language Models.", model_menu = gr.Dropdown(choices=available_models, value=model_name, label='Model')
) btn = gr.Button("Generate")
with gr.Column():
with gr.Tab('Raw'):
output_textbox = gr.Textbox(value=default_text, lines=15, label='Output')
with gr.Tab('Markdown'):
markdown = gr.Markdown()
btn.click(generate_reply, [textbox, temp_slider, length_slider, preset_menu, model_menu], [output_textbox, markdown], show_progress=True)
interface.launch(share=False, server_name="0.0.0.0") interface.launch(share=False, server_name="0.0.0.0")