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()