MattGPT commited on
Commit
f9a4722
1 Parent(s): 97172f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,33 +1,32 @@
1
  import gradio as gr
2
  from transformers import AutoConfig
3
 
4
- # Predefined list of models
5
  model_list = ["bert-base-uncased", "gpt2", "distilbert-base-uncased"]
6
 
7
- def update_model_list(new_model):
8
- if new_model not in model_list:
9
  model_list.append(new_model)
10
  return model_list
11
 
12
  def create_config(model_name, num_labels, use_cache):
 
 
13
  config = AutoConfig.from_pretrained(model_name, num_labels=num_labels, use_cache=use_cache)
14
  return str(config)
15
 
16
  with gr.Blocks() as demo:
17
  gr.Markdown("## Config Class - Transformers")
18
  with gr.Row():
19
- model_dropdown = gr.Dropdown(label="Select a Model", choices=model_list)
20
- add_model_box = gr.Textbox(label="Add a New Model")
21
  add_model_button = gr.Button("Add Model")
22
- num_labels = gr.Number(label="Number of Labels", default=2)
23
- use_cache = gr.Checkbox(label="Use Cache", default=True)
24
- output = gr.Textbox(label="Config Output", readonly=True)
25
  submit_button = gr.Button("Create Config")
26
 
27
- # Logic to add a new model to the dropdown
28
- add_model_button.click(fn=update_model_list, inputs=add_model_box, outputs=model_dropdown)
29
-
30
- # Logic to create a config
31
- submit_button.click(fn=create_config, inputs=[model_dropdown, num_labels, use_cache], outputs=output)
32
 
33
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import AutoConfig
3
 
4
+ # Initialize with some common models
5
  model_list = ["bert-base-uncased", "gpt2", "distilbert-base-uncased"]
6
 
7
+ def add_model_to_list(new_model):
8
+ if new_model and new_model not in model_list:
9
  model_list.append(new_model)
10
  return model_list
11
 
12
  def create_config(model_name, num_labels, use_cache):
13
+ if model_name not in model_list:
14
+ model_list.append(model_name)
15
  config = AutoConfig.from_pretrained(model_name, num_labels=num_labels, use_cache=use_cache)
16
  return str(config)
17
 
18
  with gr.Blocks() as demo:
19
  gr.Markdown("## Config Class - Transformers")
20
  with gr.Row():
21
+ model_dropdown = gr.Dropdown(label="Select a Model", choices=model_list, value=model_list[0])
22
+ new_model_input = gr.Textbox(label="Add a New Model", placeholder="Enter model name")
23
  add_model_button = gr.Button("Add Model")
24
+ num_labels_input = gr.Number(label="Number of Labels", value=2)
25
+ use_cache_input = gr.Checkbox(label="Use Cache", value=True)
26
+ output_area = gr.Textbox(label="Config Output", readonly=True)
27
  submit_button = gr.Button("Create Config")
28
 
29
+ add_model_button.click(fn=add_model_to_list, inputs=new_model_input, outputs=model_dropdown)
30
+ submit_button.click(fn=create_config, inputs=[model_dropdown, num_labels_input, use_cache_input], outputs=output_area)
 
 
 
31
 
32
  demo.launch()