File size: 2,626 Bytes
ed0dca2 a40632d bdf3e70 30da7cc 9e53c43 b1cf10f 30da7cc b1cf10f a40632d 30da7cc a5e8844 30da7cc 9e53c43 bdf3e70 ed0dca2 52589e7 9e53c43 52589e7 9e53c43 52589e7 3bd828b c7fc37b 3bd828b c59143e 52589e7 c59143e 52589e7 c59143e 52589e7 c59143e a5e8844 c59143e 52589e7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
##################################### Imports ######################################
# Generic imports
import gradio as gr
# Module imports
from utilities.setup import get_json_cfg
from utilities.templates import prompt_template
########################### Global objects and functions ###########################
conf = get_json_cfg()
def dropdown_visibility(radio):
value = radio
if value == "Predefined Dataset":
return gr.Dropdown(visible=bool(1))
else:
return gr.Dropdown(visible=bool(0))
def upload_visibility(radio):
value = radio
if value == "Upload Your Own":
return gr.UploadButton(visible=bool(1)) #make it visible
else:
return gr.UploadButton(visible=bool(0))
def greet(model_name, inject_prompt, name, dataset):
"""The model call"""
return f"Hello {name}!! Using model: {model_name} with template: {inject_prompt}"
##################################### App UI #######################################
with gr.Blocks() as demo:
##### Title Block #####
gr.Markdown("# Instruction Tuning with Unsloth")
##### Model Inputs #####
# Select Model
modelnames = conf['model']['choices']
model_name = gr.Dropdown(label="Supported Models",
choices=modelnames,
value=modelnames[0])
# Prompt template
inject_prompt = gr.Textbox(label="Prompt Template",
value=prompt_template())
# Prompt Input
name_input = gr.Textbox(label="Your Name")
# Dataset choice
dataset_choice = gr.Radio(label="Choose Dataset", choices=["Predefined Dataset", "Upload Your Own"], value="Predefined Dataset")
dataset_predefined = gr.Dropdown(label="Predefined Dataset", choices=['1', '2', '3'], value='1', visible=True)
dataset_upload = gr.UploadButton(label="Upload Dataset", file_types=[".pdf",".csv",".jsonl"], visible=False) # gr.File(label="Upload Dataset", visible=False)
dataset_choice.change(dropdown_visibility, dataset_choice, dataset_predefined)
dataset_choice.change(upload_visibility, dataset_choice, dataset_upload)
##### Model Outputs #####
# Text output
output = gr.Textbox(label="Output")
##### Execution #####
# Setup button
tune_btn = gr.Button("Start Fine Tuning")
# Execute button
tune_btn.click(fn=greet,
inputs=[model_name, inject_prompt, name_input, dataset_predefined],
outputs=output)
##################################### Launch #######################################
if __name__ == "__main__":
demo.launch()
|