suryadev1 commited on
Commit
8f1a3f5
·
verified ·
1 Parent(s): 473212a

Update app.py

Browse files

changed the visualize button

Files changed (1) hide show
  1. app.py +17 -42
app.py CHANGED
@@ -14,7 +14,6 @@ from matplotlib.figure import Figure
14
  import csv
15
  import os
16
  from huggingface_hub import login
17
-
18
  # import os
19
  # Define the function to process the input file and model selection
20
 
@@ -245,13 +244,15 @@ def process_file(model_name,inc_slider,progress=Progress(track_tqdm=True)):
245
  print(f"CSV file '{filename}' created successfully.")
246
  full_path = os.path.join("fileHandler", filename)
247
  # upload_to_dataset(full_path)
248
-
 
249
  task_type_map = {0: "ER", 1: "ME"}
250
  label_map = {0: "unsuccessful", 1: "successful"}
251
 
252
  # -------------------------------
253
  # 1. Where tlb == plb
254
  # -------------------------------
 
255
  for label in [0, 1]:
256
  # All strategies
257
  matching_indices = [i for i in range(len(tlb)) if tlb[i] == plb[i] == label]
@@ -844,7 +845,7 @@ def process_file(model_name,inc_slider,progress=Progress(track_tqdm=True)):
844
 
845
 
846
  # return text_output,text_output_sampled_auc,fig,fig_task1,fig_task2,fig_hist1,fig_hist2
847
- return text_output,fig,fig_task1,fig_task2
848
  # List of models for the dropdown menu
849
 
850
  # models = ["ASTRA-FT-HGR", "ASTRA-FT-LGR", "ASTRA-FT-FULL"]
@@ -1321,48 +1322,22 @@ with gr.Blocks(theme='gstaff/sketch', css=custom_css) as demo:
1321
  opt1_pie = gr.Plot(label="ER")
1322
  opt2_pie = gr.Plot(label="ME")
1323
 
 
1324
  with gr.Row():
1325
  with gr.Column():
1326
- # gr.Markdown("Select strategy filters and click Generate")
1327
- task_type_radio = gr.Dropdown(
1328
- choices=["ER", "ME", "All"],
1329
- label="Filter by Problem Type",
1330
- interactive=True
1331
- )
1332
- source_radio = gr.Checkbox(
1333
- label="Predicted Labels",
1334
- value=True
1335
- )
1336
- generate_button = gr.Button("Generate Strategies")
1337
-
1338
- # with gr.Row():
1339
- with gr.Column():
1340
- with gr.Group(visible=True) as file_output_group:
1341
-
1342
- visualize_markdown = gr.Markdown(visible=True)
1343
-
1344
-
1345
- def handle_generate(task_type_dropdown, use_predicted):
1346
- label_source = "Predicted" if use_predicted else "Ground Truth"
1347
- file_success_path, file_unsuccess_path,file_all_path, viz_link = provide_file_paths(task_type_dropdown, label_source)
1348
- delete_files()
1349
- print("writing file to the dataset",file_success_path)
1350
- # full_path = os.path.join("fileHandler", filename)
1351
-
1352
- upload_to_dataset(file_success_path)
1353
- print("writing file to the dataset",file_unsuccess_path)
1354
- upload_to_dataset(file_unsuccess_path)
1355
- print("writing file to the dataset",file_all_path)
1356
- upload_to_dataset(file_all_path)
1357
- return viz_link,gr.update(visible=True)
1358
-
1359
-
1360
- generate_button.click(
1361
- fn=handle_generate,
1362
- inputs=[task_type_radio, source_radio],
1363
- outputs=[ visualize_markdown,file_output_group]
1364
  )
1365
 
 
1366
  btn.click(
1367
  fn=lambda model, increment: (
1368
  *process_file(model, increment), # Unpack all outputs from process_file
@@ -1374,7 +1349,7 @@ with gr.Blocks(theme='gstaff/sketch', css=custom_css) as demo:
1374
  gr.update(visible=False) # Hide visualize markdown
1375
  ),
1376
  inputs=[model_dropdown, increment_slider],
1377
- outputs=[output_text, plot_output, opt1_pie, opt2_pie, task_type_radio,source_radio, visualize_markdown]
1378
  )
1379
 
1380
 
 
14
  import csv
15
  import os
16
  from huggingface_hub import login
 
17
  # import os
18
  # Define the function to process the input file and model selection
19
 
 
244
  print(f"CSV file '{filename}' created successfully.")
245
  full_path = os.path.join("fileHandler", filename)
246
  # upload_to_dataset(full_path)
247
+
248
+ upload_to_dataset(full_path)
249
  task_type_map = {0: "ER", 1: "ME"}
250
  label_map = {0: "unsuccessful", 1: "successful"}
251
 
252
  # -------------------------------
253
  # 1. Where tlb == plb
254
  # -------------------------------
255
+ delete_files()
256
  for label in [0, 1]:
257
  # All strategies
258
  matching_indices = [i for i in range(len(tlb)) if tlb[i] == plb[i] == label]
 
845
 
846
 
847
  # return text_output,text_output_sampled_auc,fig,fig_task1,fig_task2,fig_hist1,fig_hist2
848
+ return text_output,fig,fig_task1,fig_task2,gr.update(visible=True)
849
  # List of models for the dropdown menu
850
 
851
  # models = ["ASTRA-FT-HGR", "ASTRA-FT-LGR", "ASTRA-FT-FULL"]
 
1322
  opt1_pie = gr.Plot(label="ER")
1323
  opt2_pie = gr.Plot(label="ME")
1324
 
1325
+
1326
  with gr.Row():
1327
  with gr.Column():
1328
+ redirect_button = gr.Button("Click to Visualization Strategies", visible=False)
1329
+
1330
+ redirect_button.click(
1331
+ None,
1332
+ inputs=[],
1333
+ outputs=[],
1334
+ js="""() => {
1335
+ window.open("https://path-analysis.vercel.app", "_blank");
1336
+ return "ok"; // must return something
1337
+ }"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1338
  )
1339
 
1340
+
1341
  btn.click(
1342
  fn=lambda model, increment: (
1343
  *process_file(model, increment), # Unpack all outputs from process_file
 
1349
  gr.update(visible=False) # Hide visualize markdown
1350
  ),
1351
  inputs=[model_dropdown, increment_slider],
1352
+ outputs=[output_text, plot_output, opt1_pie, opt2_pie,redirect_button]
1353
  )
1354
 
1355