tykiww commited on
Commit
94fc903
·
verified ·
1 Parent(s): 598c68a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -43
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
- ##### Title Block #####
26
- gr.Markdown("# Instruction Tuning with Unsloth")
 
 
 
 
 
 
 
27
 
28
- ##### Model Inputs #####
 
 
 
29
 
30
- # Select Model
31
- model_name = gr.Dropdown(label="Model", choices=conf['model']['choices'], value="gpt2")
32
- # Prompt template
33
- prompt_template = gr.Textbox(label="Prompt Template", value="Instruction: {0}\nOutput: {1}")
34
- # Prompt Input
35
- name_input = gr.Textbox(label="Your Name")
36
- # Dataset choice
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
- # Text output
56
- output = gr.Textbox(label="Output")
57
-
58
- ##### Execution #####
 
 
 
 
59
 
60
- # Setup button
61
- tune_btn = gr.Button("Start Fine Tuning")
62
- # Execute button
63
- tune_btn.click(fn=greet,
64
- inputs=[model_name, prompt_template, name_input, dataset_file],
65
- outputs=output)
66
 
67
- # Update visibility based on user choice
68
- dataset_choice.change(toggle_dataset_visibility, inputs=[dataset_choice], outputs=[])
69
 
70
- ##################################### Launch #######################################
 
 
71
 
72
- if __name__ == "__main__":
73
- demo.launch()
 
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)