tykiww commited on
Commit
7b89069
1 Parent(s): 7a117c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -105
app.py CHANGED
@@ -62,6 +62,13 @@ class get_datasets:
62
 
63
 
64
 
 
 
 
 
 
 
 
65
 
66
  def train(model_name,
67
  inject_prompt,
@@ -97,124 +104,135 @@ def submit_weights(model, repository, model_out_name, token):
97
 
98
  ##################################### App UI #######################################
99
 
 
 
100
  def main():
101
  with gr.Blocks() as demo:
102
-
103
- ##### Title Block #####
104
- gr.Markdown("# SLM Instruction Tuning with Unsloth")
105
-
106
- ##### Initial Model Inputs #####
107
- gr.Markdown("### Model Inputs")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
- # Select Model
110
- modelnames = conf['model']['choices']
111
- model_name = gr.Dropdown(label="Supported Models",
112
- choices=modelnames,
113
- value=modelnames[0])
114
- # Prompt template
115
- inject_prompt = gr.Textbox(label="Prompt Template",
116
- value=prompt_template())
117
- # Dataset choice
118
- dataset_choice = gr.Radio(label="Choose Dataset",
119
- choices=["Hugging Face Hub Dataset", "Upload Your Own"],
120
- value="Hugging Face Hub Dataset")
121
-
122
- dataset_predefined = gr.Textbox(label="Hugging Face Hub Training Dataset",
123
- value='yahma/alpaca-cleaned',
124
- visible=True)
125
 
126
- dataset_predefined_load = gr.Button("Upload Dataset (.csv, .jsonl, or .txt)")
127
-
128
- dataset_uploaded_load = gr.UploadButton(label="Upload Dataset (.csv, .jsonl, or .txt)",
129
- file_types=[".csv",".jsonl", ".txt"],
130
- visible=False)
131
- data_snippet = gr.Markdown()
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
- dataset_choice.change(update_visibility.textbox_vis,
134
- dataset_choice,
135
- dataset_predefined)
136
- dataset_choice.change(update_visibility.upload_vis,
137
- dataset_choice,
138
- dataset_uploaded_load)
139
- dataset_choice.change(update_visibility.textbox_button_vis,
140
- dataset_choice,
141
- dataset_predefined_load)
142
 
143
- # Dataset button
144
- dataset_predefined_load.click(fn=get_datasets.predefined_dataset,
145
- inputs=dataset_predefined,
146
- outputs=data_snippet)
147
-
148
- dataset_uploaded_load.click(fn=get_datasets.uploaded_dataset,
149
- inputs=dataset_uploaded_load,
150
- outputs=data_snippet)
151
-
152
-
153
-
154
 
155
-
156
- ##### Model Parameter Inputs #####
157
- gr.Markdown("### Model Parameter Selection")
158
- # Parameters
159
- data_field = gr.Textbox(label="Dataset Training Field Name",
160
- value=conf['model']['general']["dataset_text_field"])
161
- max_seq_length = gr.Textbox(label="Maximum sequence length",
162
- value=conf['model']['general']["max_seq_length"])
163
- random_seed = gr.Textbox(label="Seed",
164
- value=conf['model']['general']["seed"])
165
- num_epochs = gr.Textbox(label="Training Epochs",
166
- value=conf['model']['general']["num_train_epochs"])
167
- max_steps = gr.Textbox(label="Maximum steps",
168
- value=conf['model']['general']["max_steps"])
169
- repository = gr.Textbox(label="Repository Name",
170
- value=conf['model']['general']["repository"])
171
- model_out_name = gr.Textbox(label="Model Output Name",
172
- value=conf['model']['general']["model_name"])
173
-
174
- # Hyperparameters (allow selection, but hide in accordion.)
175
- with gr.Accordion("Advanced Tuning", open=False):
176
-
177
- sftparams = conf['model']['general']
178
- # accordion container content
179
- dict_string = json.dumps(dict(conf['model']['peft']), indent=4)
180
- peft = gr.Textbox(label="PEFT Parameters (json)", value=dict_string)
181
-
182
- dict_string = json.dumps(dict(conf['model']['sft']), indent=4)
183
- sft = gr.Textbox(label="SFT Parameters (json)", value=dict_string)
184
 
185
- ##### Execution #####
186
-
187
- # Setup buttons
188
- tune_btn = gr.Button("Start Fine Tuning")
189
- gr.Markdown("### Model Progress")
190
- # Text output (for now)
191
- output = gr.Textbox(label="Output")
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
- # Data retrieval
 
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
- # Execute buttons
198
- tune_btn.click(fn=train,
199
- inputs=[model_name,
200
- inject_prompt,
201
- dataset_predefined,
202
- peft,
203
- sft,
204
- max_seq_length,
205
- random_seed,
206
- num_epochs,
207
- max_steps,
208
- data_field,
209
- repository,
210
- model_out_name
211
- ],
212
- outputs=output)
213
- # stop button
214
-
215
- # submit button
216
-
217
 
 
 
 
 
218
  # Launch baby
219
  demo.launch()
220
 
 
62
 
63
 
64
 
65
+ def show_about():
66
+ return "## About\n\nThis is an application for uploading datasets. You can upload files in .csv, .jsonl, or .txt format. The app will process the file and provide feedback."
67
+
68
+ def show_upload():
69
+ return "## Upload\n\nUse the button below to upload your dataset."
70
+
71
+
72
 
73
  def train(model_name,
74
  inject_prompt,
 
104
 
105
  ##################################### App UI #######################################
106
 
107
+
108
+
109
  def main():
110
  with gr.Blocks() as demo:
111
+
112
+ with gr.Row():
113
+ with gr.Column(scale=1, min_width=200): # Sidebar navigation
114
+ gr.Markdown("### Navigation")
115
+ btn_about = gr.Button("About")
116
+ btn_upload = gr.Button("Upload Dataset")
117
+ with gr.Column(scale=4): # Main content area
118
+ ##### Title Block #####
119
+ gr.Markdown("# SLM Instruction Tuning with Unsloth")
120
+
121
+ ##### Initial Model Inputs #####
122
+ gr.Markdown("### Model Inputs")
123
+
124
+ # Select Model
125
+ modelnames = conf['model']['choices']
126
+ model_name = gr.Dropdown(label="Supported Models",
127
+ choices=modelnames,
128
+ value=modelnames[0])
129
+ # Prompt template
130
+ inject_prompt = gr.Textbox(label="Prompt Template",
131
+ value=prompt_template())
132
+ # Dataset choice
133
+ dataset_choice = gr.Radio(label="Choose Dataset",
134
+ choices=["Hugging Face Hub Dataset", "Upload Your Own"],
135
+ value="Hugging Face Hub Dataset")
136
 
137
+ dataset_predefined = gr.Textbox(label="Hugging Face Hub Training Dataset",
138
+ value='yahma/alpaca-cleaned',
139
+ visible=True)
140
+
141
+ dataset_predefined_load = gr.Button("Upload Dataset (.csv, .jsonl, or .txt)")
 
 
 
 
 
 
 
 
 
 
 
142
 
143
+ dataset_uploaded_load = gr.UploadButton(label="Upload Dataset (.csv, .jsonl, or .txt)",
144
+ file_types=[".csv",".jsonl", ".txt"],
145
+ visible=False)
146
+ data_snippet = gr.Markdown()
147
+
148
+ dataset_choice.change(update_visibility.textbox_vis,
149
+ dataset_choice,
150
+ dataset_predefined)
151
+ dataset_choice.change(update_visibility.upload_vis,
152
+ dataset_choice,
153
+ dataset_uploaded_load)
154
+ dataset_choice.change(update_visibility.textbox_button_vis,
155
+ dataset_choice,
156
+ dataset_predefined_load)
157
+
158
+ # Dataset button
159
+ dataset_predefined_load.click(fn=get_datasets.predefined_dataset,
160
+ inputs=dataset_predefined,
161
+ outputs=data_snippet)
162
 
163
+ dataset_uploaded_load.click(fn=get_datasets.uploaded_dataset,
164
+ inputs=dataset_uploaded_load,
165
+ outputs=data_snippet)
 
 
 
 
 
 
166
 
 
 
 
 
 
 
 
 
 
 
 
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
+
 
 
 
 
 
 
170
 
171
+ ##### Model Parameter Inputs #####
172
+ gr.Markdown("### Model Parameter Selection")
173
+ # Parameters
174
+ data_field = gr.Textbox(label="Dataset Training Field Name",
175
+ value=conf['model']['general']["dataset_text_field"])
176
+ max_seq_length = gr.Textbox(label="Maximum sequence length",
177
+ value=conf['model']['general']["max_seq_length"])
178
+ random_seed = gr.Textbox(label="Seed",
179
+ value=conf['model']['general']["seed"])
180
+ num_epochs = gr.Textbox(label="Training Epochs",
181
+ value=conf['model']['general']["num_train_epochs"])
182
+ max_steps = gr.Textbox(label="Maximum steps",
183
+ value=conf['model']['general']["max_steps"])
184
+ repository = gr.Textbox(label="Repository Name",
185
+ value=conf['model']['general']["repository"])
186
+ model_out_name = gr.Textbox(label="Model Output Name",
187
+ value=conf['model']['general']["model_name"])
188
 
189
+ # Hyperparameters (allow selection, but hide in accordion.)
190
+ with gr.Accordion("Advanced Tuning", open=False):
191
 
192
+ sftparams = conf['model']['general']
193
+ # accordion container content
194
+ dict_string = json.dumps(dict(conf['model']['peft']), indent=4)
195
+ peft = gr.Textbox(label="PEFT Parameters (json)", value=dict_string)
196
+
197
+ dict_string = json.dumps(dict(conf['model']['sft']), indent=4)
198
+ sft = gr.Textbox(label="SFT Parameters (json)", value=dict_string)
199
+
200
+ ##### Execution #####
201
+
202
+ # Setup buttons
203
+ tune_btn = gr.Button("Start Fine Tuning")
204
+ gr.Markdown("### Model Progress")
205
+ # Text output (for now)
206
+ output = gr.Textbox(label="Output")
207
+
208
+
209
+ # Data retrieval
210
+
211
+
212
+ # Execute buttons
213
+ tune_btn.click(fn=train,
214
+ inputs=[model_name,
215
+ inject_prompt,
216
+ dataset_predefined,
217
+ peft,
218
+ sft,
219
+ max_seq_length,
220
+ random_seed,
221
+ num_epochs,
222
+ max_steps,
223
+ data_field,
224
+ repository,
225
+ model_out_name
226
+ ],
227
+ outputs=output)
228
+ # stop button
229
 
230
+ # submit button
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
+ # Link buttons to functions
233
+ btn_about.click(fn=show_about, outputs=main_content)
234
+ btn_upload.click(fn=lambda: ("", gr.update(visible=True)), outputs=[main_content, dataset_uploaded_load])
235
+
236
  # Launch baby
237
  demo.launch()
238