tykiww commited on
Commit
a40632d
·
verified ·
1 Parent(s): d116aef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -11
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('config/config.json', 'r') as file:
14
  config = json.load(file)
15
 
16
  return config
17
 
18
- print(get_json_cfg())
19
- dirname = ' '.join(os.listdir())
 
 
 
20
 
21
  def greet(model_name, prompt_template, name):
22
- return f"Hello {name}!! Using model: {model_name} with template: {prompt_template} and {dirname}"
23
 
24
- model_choices = ["gpt2", "bert-base-uncased", "llama3-8b"]
25
 
26
 
27
  ##################################### App UI #######################################
28
  with gr.Blocks() as demo:
 
 
29
  gr.Markdown("# Instruction Tuning with Unsloth")
30
- model_name = gr.Dropdown(label="Model", choices=model_choices, value="gpt2")
 
 
 
 
 
31
  prompt_template = gr.Textbox(label="Prompt Template", value="Instruction: {0}\nOutput: {1}")
 
32
  name_input = gr.Textbox(label="Your Name")
33
-
34
- greet_btn = gr.Button("Greet")
 
 
35
  output = gr.Textbox(label="Output")
36
 
37
- greet_btn.click(fn=greet,
38
- inputs=[model_name, prompt_template, name_input],
39
- outputs=output)
 
 
 
 
 
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 #######################################