File size: 1,276 Bytes
6d1f41e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import gradio as gr
from transformers import AutoConfig
# Predefined list of models
model_list = ["bert-base-uncased", "gpt2", "distilbert-base-uncased"]
def update_model_list(new_model):
if new_model not in model_list:
model_list.append(new_model)
return model_list
def create_config(model_name, num_labels, use_cache):
config = AutoConfig.from_pretrained(model_name, num_labels=num_labels, use_cache=use_cache)
return str(config)
with gr.Blocks() as demo:
gr.Markdown("## Config Class - Transformers")
with gr.Row():
model_dropdown = gr.Dropdown(label="Select a Model", choices=model_list)
add_model_box = gr.Textbox(label="Add a New Model")
add_model_button = gr.Button("Add Model")
num_labels = gr.Number(label="Number of Labels", default=2)
use_cache = gr.Checkbox(label="Use Cache", default=True)
output = gr.Textbox(label="Config Output", readonly=True)
submit_button = gr.Button("Create Config")
# Logic to add a new model to the dropdown
add_model_button.click(fn=update_model_list, inputs=add_model_box, outputs=model_dropdown)
# Logic to create a config
submit_button.click(fn=create_config, inputs=[model_dropdown, num_labels, use_cache], outputs=output)
demo.launch()
|