felipekitamura commited on
Commit
7e8ba8a
·
verified ·
1 Parent(s): 49d4f15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -1,8 +1,11 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import os
 
4
  from omnibin import generate_binary_classification_report
5
- import tempfile
 
 
6
 
7
  def process_csv(csv_file):
8
  # Read the CSV file
@@ -13,20 +16,25 @@ def process_csv(csv_file):
13
  if not all(col in df.columns for col in required_columns):
14
  raise ValueError("CSV file must contain 'y_true' and 'y_pred' columns")
15
 
16
- # Create a temporary directory for the output
17
- with tempfile.TemporaryDirectory() as temp_dir:
18
- # Generate the report
19
- report_path = generate_binary_classification_report(
20
- y_true=df['y_true'].values,
21
- y_scores=df['y_pred'].values,
22
- output_path=os.path.join(temp_dir, "classification_report.pdf"),
23
- n_bootstrap=1000,
24
- random_seed=42,
25
- dpi=72
26
- )
27
-
28
- # Return the PDF file
29
- return report_path
 
 
 
 
 
30
 
31
  # Create the Gradio interface
32
  iface = gr.Interface(
 
1
  import gradio as gr
2
  import pandas as pd
3
  import os
4
+ import shutil
5
  from omnibin import generate_binary_classification_report
6
+
7
+ # Define results directory
8
+ RESULTS_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "results")
9
 
10
  def process_csv(csv_file):
11
  # Read the CSV file
 
16
  if not all(col in df.columns for col in required_columns):
17
  raise ValueError("CSV file must contain 'y_true' and 'y_pred' columns")
18
 
19
+ # Clean up results directory if it exists
20
+ if os.path.exists(RESULTS_DIR):
21
+ shutil.rmtree(RESULTS_DIR)
22
+
23
+ # Create fresh results directory
24
+ os.makedirs(RESULTS_DIR, exist_ok=True)
25
+
26
+ # Generate the report
27
+ report_path = generate_binary_classification_report(
28
+ y_true=df['y_true'].values,
29
+ y_scores=df['y_pred'].values,
30
+ output_path=os.path.join(RESULTS_DIR, "classification_report.pdf"),
31
+ n_bootstrap=1000,
32
+ random_seed=42,
33
+ dpi=72
34
+ )
35
+
36
+ # Return the PDF file
37
+ return report_path
38
 
39
  # Create the Gradio interface
40
  iface = gr.Interface(