Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,45 +16,47 @@ from utilities.templates import prompt_template
|
|
16 |
|
17 |
conf = get_json_cfg()
|
18 |
|
19 |
-
def textbox_visibility(radio):
|
20 |
-
value = radio
|
21 |
-
if value == "Hugging Face Hub Dataset":
|
22 |
-
return gr.Dropdown(visible=bool(1))
|
23 |
-
else:
|
24 |
-
return gr.Dropdown(visible=bool(0))
|
25 |
-
|
26 |
-
def textbox_button_visibility(radio):
|
27 |
-
value = radio
|
28 |
-
if value == "Hugging Face Hub Dataset":
|
29 |
-
return gr.Button(visible=bool(1))
|
30 |
-
else:
|
31 |
-
return gr.Button(visible=bool(0))
|
32 |
-
|
33 |
-
def upload_visibility(radio):
|
34 |
-
value = radio
|
35 |
-
if value == "Upload Your Own":
|
36 |
-
return gr.UploadButton(visible=bool(1)) #make it visible
|
37 |
-
else:
|
38 |
-
return gr.UploadButton(visible=bool(0))
|
39 |
-
|
40 |
-
|
41 |
|
|
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
-
def get_predefined_dataset(dataset_name):
|
46 |
-
dataset = load_dataset(dataset_name, split = "train") #dataset_name
|
47 |
-
return dataset[0]['output'][0:100]
|
48 |
|
|
|
49 |
|
50 |
-
def
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
|
60 |
|
@@ -136,22 +138,22 @@ def main():
|
|
136 |
value=conf['model']['general']["dataset_text_field"])
|
137 |
|
138 |
data_snippet = gr.Markdown()
|
139 |
-
dataset_choice.change(textbox_visibility,
|
140 |
dataset_choice,
|
141 |
dataset_predefined)
|
142 |
-
dataset_choice.change(upload_visibility,
|
143 |
dataset_choice,
|
144 |
dataset_uploaded_load)
|
145 |
-
dataset_choice.change(textbox_button_visibility,
|
146 |
dataset_choice,
|
147 |
dataset_predefined_load)
|
148 |
|
149 |
# Dataset button
|
150 |
-
dataset_predefined_load.click(fn=
|
151 |
inputs=dataset_predefined,
|
152 |
outputs=data_snippet)
|
153 |
|
154 |
-
dataset_uploaded_load.click(fn=get_uploaded_dataset,
|
155 |
inputs=dataset_uploaded_load,
|
156 |
outputs=data_snippet)
|
157 |
|
|
|
16 |
|
17 |
conf = get_json_cfg()
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
class update_visibility:
|
21 |
|
22 |
+
def textbox_visibility(radio):
|
23 |
+
value = radio
|
24 |
+
if value == "Hugging Face Hub Dataset":
|
25 |
+
return gr.Dropdown(visible=bool(1))
|
26 |
+
else:
|
27 |
+
return gr.Dropdown(visible=bool(0))
|
28 |
+
|
29 |
+
def textbox_button_visibility(radio):
|
30 |
+
value = radio
|
31 |
+
if value == "Hugging Face Hub Dataset":
|
32 |
+
return gr.Button(visible=bool(1))
|
33 |
+
else:
|
34 |
+
return gr.Button(visible=bool(0))
|
35 |
+
|
36 |
+
def upload_visibility(radio):
|
37 |
+
value = radio
|
38 |
+
if value == "Upload Your Own":
|
39 |
+
return gr.UploadButton(visible=bool(1)) #make it visible
|
40 |
+
else:
|
41 |
+
return gr.UploadButton(visible=bool(0))
|
42 |
|
43 |
|
|
|
|
|
|
|
44 |
|
45 |
+
class get_datasets:
|
46 |
|
47 |
+
def predefined_dataset(dataset_name):
|
48 |
+
dataset = load_dataset(dataset_name, split = "train") #dataset_name
|
49 |
+
return dataset[0]['output'][0:100]
|
50 |
+
|
51 |
+
|
52 |
+
def uploaded_dataset(file):
|
53 |
+
dataset = []
|
54 |
+
print(file)
|
55 |
+
with open(file,'r') as file:
|
56 |
+
for line in file:
|
57 |
+
dataset.append(json.loads(line.strip()))
|
58 |
+
print(dataset[0]['query'])
|
59 |
+
return dataset[0]['query']
|
60 |
|
61 |
|
62 |
|
|
|
138 |
value=conf['model']['general']["dataset_text_field"])
|
139 |
|
140 |
data_snippet = gr.Markdown()
|
141 |
+
dataset_choice.change(update_visibility.textbox_visibility,
|
142 |
dataset_choice,
|
143 |
dataset_predefined)
|
144 |
+
dataset_choice.change(update_visibility.upload_visibility,
|
145 |
dataset_choice,
|
146 |
dataset_uploaded_load)
|
147 |
+
dataset_choice.change(update_visibility.textbox_button_visibility,
|
148 |
dataset_choice,
|
149 |
dataset_predefined_load)
|
150 |
|
151 |
# Dataset button
|
152 |
+
dataset_predefined_load.click(fn=get_datasets.predefined_dataset,
|
153 |
inputs=dataset_predefined,
|
154 |
outputs=data_snippet)
|
155 |
|
156 |
+
dataset_uploaded_load.click(fn=get_datasets.get_uploaded_dataset,
|
157 |
inputs=dataset_uploaded_load,
|
158 |
outputs=data_snippet)
|
159 |
|