MattGPT commited on
Commit
6d1f41e
1 Parent(s): ef20a1b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()