tykiww commited on
Commit
30da7cc
1 Parent(s): 20f6573

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -46
app.py CHANGED
@@ -1,21 +1,30 @@
1
  ##################################### Imports ######################################
2
  # Generic imports
3
  import gradio as gr
4
- import json
5
- import os
6
 
7
- ########################### Global objects and functions ###########################
 
8
 
9
- def get_json_cfg():
10
- """Retrieve configuration file"""
11
- config_path = os.getenv('CONFIG_PATH')
12
- with open(config_path, 'r') as file:
13
- config = json.load(file)
14
- return config
15
 
16
  conf = get_json_cfg()
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  def greet(model_name, prompt_template, name, dataset):
 
19
  return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}"
20
 
21
  ##################################### App UI #######################################
@@ -36,46 +45,9 @@ with gr.Blocks() as demo:
36
  dataset_choice = gr.Radio(label="Choose Dataset", choices=["Predefined Dataset", "Upload Your Own"], value="Predefined Dataset")
37
  dataset_predefined = gr.Dropdown(label="Predefined Dataset", choices=['1', '2', '3'], value='1', visible=True)
38
  dataset_upload = gr.UploadButton(label="Upload Dataset", file_types=[".pdf",".csv",".jsonl"], visible=False) # gr.File(label="Upload Dataset", visible=False)
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
- def dropdown_visibility(radio): # Accept the event argument, even if not used
47
- value = radio # Get the selected value from the radio button
48
- if value == "Predefined Dataset":
49
- return gr.Dropdown(visible=bool(1))
50
- else:
51
- return gr.Dropdown(visible=bool(0))
52
-
53
- def upload_visibility(radio):
54
- value = radio
55
- if value == "Upload Your Own":
56
- return gr.UploadButton(visible=bool(1)) #make it visible
57
- else:
58
- return gr.UploadButton(visible=bool(0))
59
-
60
  dataset_choice.change(dropdown_visibility, dataset_choice, dataset_predefined)
61
  dataset_choice.change(upload_visibility, dataset_choice, dataset_upload)
62
 
63
- # Define function to update visibility based on dataset choice
64
- def update_visibility():
65
- choice = dataset_choice.value
66
- if choice == "Predefined Dataset":
67
- dataset_predefined.visible = True
68
- dataset_upload.visible = False
69
- elif choice == "Upload Your Own":
70
- dataset_predefined.visible = False
71
- dataset_upload.visible = True
72
-
73
- # Bind visibility update function to change event of dataset_choice
74
- dataset_choice.change(update_visibility)
75
-
76
- # Update visibility based on user choice
77
- #dataset_predefined, dataset_upload = dataset_choice.change(update_dataset_visibility, inputs=[dataset_choice], outputs=[dataset_predefined, dataset_upload])
78
-
79
  ##### Model Outputs #####
80
 
81
  # Text output
 
1
  ##################################### Imports ######################################
2
  # Generic imports
3
  import gradio as gr
 
 
4
 
5
+ # Module imports
6
+ from utilities.setup import get_json_cfg
7
 
8
+ ########################### Global objects and functions ###########################
 
 
 
 
 
9
 
10
  conf = get_json_cfg()
11
 
12
+ def dropdown_visibility(radio):
13
+ value = radio
14
+ if value == "Predefined Dataset":
15
+ return gr.Dropdown(visible=bool(1))
16
+ else:
17
+ return gr.Dropdown(visible=bool(0))
18
+
19
+ def upload_visibility(radio):
20
+ value = radio
21
+ if value == "Upload Your Own":
22
+ return gr.UploadButton(visible=bool(1)) #make it visible
23
+ else:
24
+ return gr.UploadButton(visible=bool(0))
25
+
26
  def greet(model_name, prompt_template, name, dataset):
27
+ """The model call"""
28
  return f"Hello {name}!! Using model: {model_name} with template: {prompt_template}"
29
 
30
  ##################################### App UI #######################################
 
45
  dataset_choice = gr.Radio(label="Choose Dataset", choices=["Predefined Dataset", "Upload Your Own"], value="Predefined Dataset")
46
  dataset_predefined = gr.Dropdown(label="Predefined Dataset", choices=['1', '2', '3'], value='1', visible=True)
47
  dataset_upload = gr.UploadButton(label="Upload Dataset", file_types=[".pdf",".csv",".jsonl"], visible=False) # gr.File(label="Upload Dataset", visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  dataset_choice.change(dropdown_visibility, dataset_choice, dataset_predefined)
49
  dataset_choice.change(upload_visibility, dataset_choice, dataset_upload)
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  ##### Model Outputs #####
52
 
53
  # Text output