Update app.py
Browse files
app.py
CHANGED
@@ -20,54 +20,49 @@ def greet(model_name, prompt_template, name, dataset_file):
|
|
20 |
return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}"
|
21 |
|
22 |
##################################### App UI #######################################
|
23 |
-
with gr.Blocks() as demo:
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
dataset_choice = gr.Radio(label="Choose Dataset", choices=["Predefined Dataset", "Upload Your Own"], value="Predefined Dataset")
|
38 |
-
dataset_predefined = gr.Dropdown(label="Predefined Dataset", choices=['1', '2', '3'], value='1', visible=True)
|
39 |
-
dataset_file = gr.inputs.File(label="Upload Dataset", type='file', accept=".csv,.txt", visible=False)
|
40 |
-
|
41 |
-
# Function to toggle visibility based on user choice
|
42 |
-
def toggle_dataset_visibility(choice):
|
43 |
-
if choice == "Predefined Dataset":
|
44 |
-
dataset_predefined.visible = True
|
45 |
-
dataset_file.visible = False
|
46 |
-
elif choice == "Upload Your Own":
|
47 |
-
dataset_predefined.visible = False
|
48 |
-
dataset_file.visible = True
|
49 |
-
|
50 |
-
# Initial visibility setup based on default choice
|
51 |
-
toggle_dataset_visibility(dataset_choice.value)
|
52 |
-
|
53 |
-
##### Model Outputs #####
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
tune_btn.click(fn=greet,
|
64 |
-
inputs=[model_name, prompt_template, name_input, dataset_file],
|
65 |
-
outputs=output)
|
66 |
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
|
|
20 |
return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}"
|
21 |
|
22 |
##################################### App UI #######################################
|
|
|
23 |
|
24 |
+
# Function to build the interface based on user choice
|
25 |
+
def build_interface(choice):
|
26 |
+
if choice == "Predefined Dataset":
|
27 |
+
dataset_input = gr.Dropdown(label="Predefined Dataset", choices=['1', '2', '3'], value='1', key="dataset_predefined")
|
28 |
+
elif choice == "Upload Your Own":
|
29 |
+
dataset_input = gr.File(label="Upload Dataset", accept=".csv,.txt", key="dataset_upload")
|
30 |
+
else:
|
31 |
+
dataset_input = None
|
32 |
+
return dataset_input
|
33 |
|
34 |
+
# Function to handle changes in dataset choice
|
35 |
+
def on_choice_change(choice):
|
36 |
+
interface = build_interface(choice)
|
37 |
+
update_interface(interface)
|
38 |
|
39 |
+
# Function to update the interface with new dataset input
|
40 |
+
def update_interface(dataset_input):
|
41 |
+
demo.Interface(
|
42 |
+
fn=greet,
|
43 |
+
inputs=[model_name, prompt_template, name_input, dataset_input],
|
44 |
+
outputs=output
|
45 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
# Select Model
|
48 |
+
model_name = gr.Dropdown(label="Model", choices=conf['model']['choices'], value="gpt2")
|
49 |
+
# Prompt template
|
50 |
+
prompt_template = gr.Textbox(label="Prompt Template", value="Instruction: {0}\nOutput: {1}")
|
51 |
+
# Prompt Input
|
52 |
+
name_input = gr.Textbox(label="Your Name")
|
53 |
+
# Dataset choice
|
54 |
+
dataset_choice = gr.Radio(label="Choose Dataset", choices=["Predefined Dataset", "Upload Your Own"], value="Predefined Dataset")
|
55 |
|
56 |
+
# Initial interface setup
|
57 |
+
initial_choice = dataset_choice.value
|
58 |
+
initial_interface = build_interface(initial_choice)
|
|
|
|
|
|
|
59 |
|
60 |
+
# Output textbox
|
61 |
+
output = gr.Textbox(label="Output")
|
62 |
|
63 |
+
# Setup button
|
64 |
+
tune_btn = gr.Button("Start Fine Tuning")
|
65 |
+
tune_btn.click(on_choice_change, inputs=[dataset_choice])
|
66 |
|
67 |
+
# Launch the initial interface
|
68 |
+
update_interface(initial_interface)
|