|
|
|
|
|
import gradio as gr |
|
import json |
|
import os |
|
|
|
|
|
|
|
def get_json_cfg(): |
|
"""Retrieve configuration file""" |
|
config_path = os.getenv('CONFIG_PATH') |
|
with open(config_path, 'r') as file: |
|
config = json.load(file) |
|
return config |
|
|
|
conf = get_json_cfg() |
|
|
|
def greet(model_name, prompt_template, name, dataset_file): |
|
|
|
return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}" |
|
|
|
|
|
|
|
|
|
def build_interface(choice): |
|
if choice == "Predefined Dataset": |
|
dataset_input = gr.Dropdown(label="Predefined Dataset", choices=['1', '2', '3'], value='1', key="dataset_predefined") |
|
elif choice == "Upload Your Own": |
|
dataset_input = gr.File(label="Upload Dataset", accept=".csv,.txt", key="dataset_upload") |
|
else: |
|
dataset_input = None |
|
return dataset_input |
|
|
|
|
|
def on_choice_change(choice): |
|
interface = build_interface(choice) |
|
update_interface(interface) |
|
|
|
|
|
def update_interface(dataset_input): |
|
demo.Interface( |
|
fn=greet, |
|
inputs=[model_name, prompt_template, name_input, dataset_input], |
|
outputs=output |
|
).launch() |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
|
|
gr.Markdown("# Instruction Tuning with Unsloth") |
|
|
|
|
|
|
|
|
|
model_name = gr.Dropdown(label="Model", choices=conf['model']['choices'], value="gpt2") |
|
|
|
prompt_template = gr.Textbox(label="Prompt Template", value="Instruction: {0}\nOutput: {1}") |
|
|
|
name_input = gr.Textbox(label="Your Name") |
|
|
|
dataset_choice = gr.Radio(label="Choose Dataset", choices=["Predefined Dataset", "Upload Your Own"], value="Predefined Dataset") |
|
|
|
|
|
initial_choice = dataset_choice.value |
|
initial_interface = build_interface(initial_choice) |
|
|
|
|
|
output = gr.Textbox(label="Output") |
|
|
|
|
|
tune_btn = gr.Button("Start Fine Tuning") |
|
tune_btn.click(on_choice_change, inputs=[dataset_choice]) |
|
|
|
|
|
update_interface(initial_interface) |
|
|
|
|
|
dataset_choice.change(on_choice_change, inputs=[dataset_choice]) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|