Spaces:
Sleeping
Sleeping
File size: 3,632 Bytes
ed0dca2 a40632d bdf3e70 b1cf10f bdf3e70 ed0dca2 b1cf10f a40632d b1cf10f a40632d c59143e a40632d bdf3e70 ed0dca2 52589e7 3bd828b 316e64b 6411d86 316e64b 629a117 b0e5f39 316e64b 15d1f35 3bd828b 94c21e2 5aa180d 94c21e2 5aa180d 94c21e2 5aa180d c59143e 3bd828b c59143e 52589e7 c59143e 52589e7 c59143e 52589e7 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
##################################### Imports ######################################
# Generic imports
import gradio as gr
import json
import os
########################### Global objects and functions ###########################
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):
return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}"
##################################### App UI #######################################
with gr.Blocks() as demo:
##### Title Block #####
gr.Markdown("# Instruction Tuning with Unsloth")
##### Model Inputs #####
# Select Model
model_name = gr.Dropdown(label="Model", choices=conf['model']['choices'], value="gpt2")
# Prompt template
prompt_template = gr.Textbox(label="Prompt Template", value="Instruction: {0}\nOutput: {1}")
# 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)
radio = gr.Radio(["show", "hide"], label="Choose")
text = gr.Textbox(label="This text only shows when 'show' is selected.", visible=False)
taxt = gr.Textbox(label="This text only shows when 'hide' is selected.", visible=True)
def open_visibility(radio): # Accept the event argument, even if not used
value = radio # Get the selected value from the radio button
if value == "show":
return gr.Textbox(visible=bool(1)) #make it visible
else:
return gr.Textbox(visible=bool(0))
def close_visibility(radio):
value = radio
if value == "hide":
return gr.Textbox(visible=bool(1)) #make it visible
else:
return gr.Textbox(visible=bool(0))
radio.change(open_visibility, radio, text)
radio.change(close_visibility, radio, taxt)
# Define function to update visibility based on dataset choice
def update_visibility():
choice = dataset_choice.value
if choice == "Predefined Dataset":
dataset_predefined.visible = True
dataset_upload.visible = False
elif choice == "Upload Your Own":
dataset_predefined.visible = False
dataset_upload.visible = True
# Bind visibility update function to change event of dataset_choice
dataset_choice.change(update_visibility)
# Update visibility based on user choice
#dataset_predefined, dataset_upload = dataset_choice.change(update_dataset_visibility, inputs=[dataset_choice], outputs=[dataset_predefined, 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, prompt_template, name_input, dataset_predefined],
outputs=output)
##################################### Launch #######################################
if __name__ == "__main__":
demo.launch()
|