import gradio as gr from transformers import AutoConfig # Initialize with some common models model_list = ["bert-base-uncased", "gpt2", "distilbert-base-uncased"] def add_model_to_list(new_model): if new_model and new_model not in model_list: model_list.append(new_model) return model_list def create_config(model_name, num_labels, use_cache): if model_name not in model_list: model_list.append(model_name) 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, value=model_list[0]) new_model_input = gr.Textbox(label="Add a New Model", placeholder="Enter model name") add_model_button = gr.Button("Add Model") num_labels_input = gr.Number(label="Number of Labels", value=2) use_cache_input = gr.Checkbox(label="Use Cache", value=True) output_area = gr.Textbox(label="Config Output") # Removed readonly=True submit_button = gr.Button("Create Config") add_model_button.click(fn=add_model_to_list, inputs=new_model_input, outputs=model_dropdown) submit_button.click(fn=create_config, inputs=[model_dropdown, num_labels_input, use_cache_input], outputs=output_area) demo.launch()