|
|
|
import gradio as gr |
|
from transformers import AutoConfig |
|
|
|
|
|
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 isinstance(model_name, list): |
|
model_name = model_name[0] |
|
|
|
|
|
num_labels = int(num_labels) |
|
|
|
|
|
if model_name not in model_list: |
|
model_list.append(model_name) |
|
|
|
|
|
config = AutoConfig.from_pretrained(model_name, num_labels=num_labels, use_cache='true') |
|
return str(config) |
|
|
|
|
|
with gr.Group(elem_id="UI-conf"): |
|
custom_css = """ |
|
.gradio-container { |
|
background-color: #f0f0f0; /* Light grey background */ |
|
font-family: Arial, sans-serif; |
|
} |
|
.gradio-textbox { |
|
border: 2px solid #4CAF50; /* Green border for textboxes */ |
|
border-radius: 5px; |
|
} |
|
.gradio-button { |
|
background-color: #4CAF50; /* Green background for buttons */ |
|
color: white; |
|
border: none; |
|
border-radius: 5px; |
|
padding: 10px 20px; |
|
text-align: center; |
|
text-decoration: none; |
|
display: inline-block; |
|
font-size: 16px; |
|
margin: 4px 2px; |
|
cursor: pointer; |
|
} |
|
.gradio-button:hover { |
|
background-color: #45a049; /* Darker green on hover */ |
|
} |
|
""" |
|
|
|
with gr.Blocks(css=custom_css) 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], allow_custom_value=True) |
|
|
|
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",) |
|
|
|
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() |