felipekitamura commited on
Commit
e2ad056
·
verified ·
1 Parent(s): 255682a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
9
+ df = pd.read_csv(csv_file.name)
10
+
11
+ # Check if required columns exist
12
+ required_columns = ['y_true', 'y_pred']
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(
33
+ fn=process_csv,
34
+ inputs=gr.File(label="Upload CSV file with 'y_true' and 'y_pred' columns"),
35
+ outputs=gr.File(label="Classification Report PDF"),
36
+ title="Binary Classification Report Generator",
37
+ description="Upload a CSV file containing 'y_true' and 'y_pred' columns to generate a comprehensive classification report with 6 figures.",
38
+ examples=[],
39
+ cache_examples=False
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ iface.launch()