Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
##################################### Imports ######################################
|
|
|
2 |
import gradio as gr
|
3 |
import json
|
4 |
import os
|
5 |
|
|
|
|
|
6 |
|
7 |
########################### Global objects and functions ###########################
|
8 |
|
@@ -10,33 +13,51 @@ def get_json_cfg():
|
|
10 |
"""Retrieve configuration file"""
|
11 |
|
12 |
config_path = os.getenv('CONFIG_PATH')
|
13 |
-
with open(
|
14 |
config = json.load(file)
|
15 |
|
16 |
return config
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
def greet(model_name, prompt_template, name):
|
22 |
-
return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}
|
23 |
|
24 |
-
model_choices = [
|
25 |
|
26 |
|
27 |
##################################### App UI #######################################
|
28 |
with gr.Blocks() as demo:
|
|
|
|
|
29 |
gr.Markdown("# Instruction Tuning with Unsloth")
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
prompt_template = gr.Textbox(label="Prompt Template", value="Instruction: {0}\nOutput: {1}")
|
|
|
32 |
name_input = gr.Textbox(label="Your Name")
|
33 |
-
|
34 |
-
|
|
|
|
|
35 |
output = gr.Textbox(label="Output")
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
##################################### Launch #######################################
|
|
|
1 |
##################################### Imports ######################################
|
2 |
+
# Generic imports
|
3 |
import gradio as gr
|
4 |
import json
|
5 |
import os
|
6 |
|
7 |
+
# local imports
|
8 |
+
|
9 |
|
10 |
########################### Global objects and functions ###########################
|
11 |
|
|
|
13 |
"""Retrieve configuration file"""
|
14 |
|
15 |
config_path = os.getenv('CONFIG_PATH')
|
16 |
+
with open(config_path, 'r') as file:
|
17 |
config = json.load(file)
|
18 |
|
19 |
return config
|
20 |
|
21 |
+
|
22 |
+
conf = get_json_cfg()
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
|
27 |
def greet(model_name, prompt_template, name):
|
28 |
+
return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}"
|
29 |
|
30 |
+
model_choices = conf['model']['choices']
|
31 |
|
32 |
|
33 |
##################################### App UI #######################################
|
34 |
with gr.Blocks() as demo:
|
35 |
+
|
36 |
+
##### Title Block #####
|
37 |
gr.Markdown("# Instruction Tuning with Unsloth")
|
38 |
+
|
39 |
+
##### Model Inputs #####
|
40 |
+
|
41 |
+
# Select Model
|
42 |
+
model_name = gr.Dropdown(label="Model", choices=conf['model']['choices'], value="gpt2")
|
43 |
+
# Show prompt template
|
44 |
prompt_template = gr.Textbox(label="Prompt Template", value="Instruction: {0}\nOutput: {1}")
|
45 |
+
# Prompt Input
|
46 |
name_input = gr.Textbox(label="Your Name")
|
47 |
+
|
48 |
+
##### Model Outputs #####
|
49 |
+
|
50 |
+
# Text output
|
51 |
output = gr.Textbox(label="Output")
|
52 |
|
53 |
+
##### Execution #####
|
54 |
+
|
55 |
+
# Setup button
|
56 |
+
tune_btn = gr.Button("Start Fine Tuning")
|
57 |
+
# Execute button
|
58 |
+
tune_btn.click(fn=greet,
|
59 |
+
inputs=[model_name, prompt_template, name_input],
|
60 |
+
outputs=output)
|
61 |
|
62 |
|
63 |
##################################### Launch #######################################
|