Spaces:
Sleeping
Sleeping
Update app.py
Browse fileschanged to appkly the path analysis tool function
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import hf_hub_download
|
3 |
import pickle
|
4 |
from gradio import Progress
|
5 |
import numpy as np
|
@@ -12,9 +12,39 @@ import plotly.graph_objects as go
|
|
12 |
from sklearn.metrics import roc_auc_score
|
13 |
from matplotlib.figure import Figure
|
14 |
import csv
|
|
|
|
|
|
|
15 |
# import os
|
16 |
# Define the function to process the input file and model selection
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def process_file(model_name,inc_slider,progress=Progress(track_tqdm=True)):
|
19 |
# progress = gr.Progress(track_tqdm=True)
|
20 |
|
@@ -213,6 +243,8 @@ def process_file(model_name,inc_slider,progress=Progress(track_tqdm=True)):
|
|
213 |
row_num += 1
|
214 |
|
215 |
print(f"CSV file '{filename}' created successfully.")
|
|
|
|
|
216 |
|
217 |
task_type_map = {0: "ER", 1: "ME"}
|
218 |
label_map = {0: "unsuccessful", 1: "successful"}
|
@@ -1305,26 +1337,30 @@ with gr.Blocks(theme='gstaff/sketch', css=custom_css) as demo:
|
|
1305 |
|
1306 |
# with gr.Row():
|
1307 |
with gr.Column():
|
1308 |
-
with gr.Group(visible=
|
1309 |
-
|
1310 |
-
gr.Markdown(
|
1311 |
-
file_output_success = gr.File(label=" ")
|
1312 |
-
file_output_unsuccess = gr.File(label=" ")
|
1313 |
-
file_output_all = gr.File(label=" ")
|
1314 |
-
visualize_markdown = gr.Markdown(visible=False)
|
1315 |
|
1316 |
|
1317 |
def handle_generate(task_type_dropdown, use_predicted):
|
1318 |
label_source = "Predicted" if use_predicted else "Ground Truth"
|
1319 |
file_success_path, file_unsuccess_path,file_all_path, viz_link = provide_file_paths(task_type_dropdown, label_source)
|
|
|
|
|
|
|
1320 |
|
1321 |
-
|
|
|
|
|
|
|
|
|
|
|
1322 |
|
1323 |
|
1324 |
generate_button.click(
|
1325 |
fn=handle_generate,
|
1326 |
inputs=[task_type_radio, source_radio],
|
1327 |
-
outputs=[
|
1328 |
)
|
1329 |
|
1330 |
btn.click(
|
@@ -1338,7 +1374,7 @@ with gr.Blocks(theme='gstaff/sketch', css=custom_css) as demo:
|
|
1338 |
gr.update(visible=False) # Hide visualize markdown
|
1339 |
),
|
1340 |
inputs=[model_dropdown, increment_slider],
|
1341 |
-
outputs=[output_text, plot_output, opt1_pie, opt2_pie, task_type_radio,source_radio,
|
1342 |
)
|
1343 |
|
1344 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import hf_hub_download, HfApi
|
3 |
import pickle
|
4 |
from gradio import Progress
|
5 |
import numpy as np
|
|
|
12 |
from sklearn.metrics import roc_auc_score
|
13 |
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 |
|
21 |
+
api = HfApi()
|
22 |
+
DATASET_REPO = "suryadev1/generated-csvs"
|
23 |
+
def delete_files():
|
24 |
+
repo_files = api.list_repo_files(repo_id=DATASET_REPO, repo_type="dataset")
|
25 |
+
|
26 |
+
# Step 2: delete all CSV files
|
27 |
+
for f in repo_files:
|
28 |
+
if f.endswith(".csv"):
|
29 |
+
try:
|
30 |
+
api.delete_file(
|
31 |
+
path_in_repo=f,
|
32 |
+
repo_id=DATASET_REPO,
|
33 |
+
repo_type="dataset"
|
34 |
+
)
|
35 |
+
print(f"Deleted old file: {f}")
|
36 |
+
except Exception as e:
|
37 |
+
print(f"Could not delete {f}: {e}")
|
38 |
+
def upload_to_dataset(filepath):
|
39 |
+
|
40 |
+
api.upload_file(
|
41 |
+
path_or_fileobj=filepath,
|
42 |
+
path_in_repo=os.path.basename(filepath),
|
43 |
+
repo_id=DATASET_REPO,
|
44 |
+
repo_type="dataset"
|
45 |
+
)
|
46 |
+
|
47 |
+
|
48 |
def process_file(model_name,inc_slider,progress=Progress(track_tqdm=True)):
|
49 |
# progress = gr.Progress(track_tqdm=True)
|
50 |
|
|
|
243 |
row_num += 1
|
244 |
|
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"}
|
|
|
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(
|
|
|
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 |
|