SanthiSastra commited on
Commit
b1a2e2c
·
verified ·
1 Parent(s): ab9ec7d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import io
6
+ from docx import Document
7
+ from docx.shared import Inches
8
+
9
+ def generate_report(df):
10
+ # Create Word Document
11
+ doc = Document()
12
+ doc.add_heading('Amrita Manthan: Preprocessing Report', 0)
13
+ doc.add_paragraph(f"Author: Prof. B. Santhi, SRC, SASTRA")
14
+
15
+ # Data Description
16
+ doc.add_heading('1. Data Description', level=1)
17
+ description = df.describe().to_string()
18
+ doc.add_paragraph(description)
19
+
20
+ # Missing Values
21
+ doc.add_heading('2. Preprocessing: Missing Values', level=1)
22
+ null_data = df.isnull().sum().to_string()
23
+ doc.add_paragraph(null_data)
24
+
25
+ report_path = "preprocessing_report.docx"
26
+ doc.save(report_path)
27
+ return report_path
28
+
29
+ def process_data(file):
30
+ if file is None:
31
+ return None, "Please upload a CSV file.", None, None
32
+
33
+ # Load Data
34
+ df = pd.read_csv(file.name)
35
+
36
+ # 1. EDA: Basic Stats
37
+ desc = df.describe(include='all').reset_index()
38
+
39
+ # 2. EDA: Correlation Plot
40
+ plt.figure(figsize=(10, 6))
41
+ sns.heatmap(df.corr(numeric_only=True), annot=True, cmap='coolwarm')
42
+ plt.tight_layout()
43
+ plot_path = "eda_plot.png"
44
+ plt.savefig(plot_path)
45
+ plt.close()
46
+
47
+ # 3. Generate Docx
48
+ report = generate_report(df)
49
+
50
+ return df.head(10), desc, plot_path, report
51
+
52
+ # --- Gradio UI Design ---
53
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
54
+ # Header Section
55
+ with gr.Column(elem_id="header"):
56
+ gr.Image("sastra_logo.jpg", width=150, container=False) # Ensure file exists
57
+ gr.Markdown("<h1 style='text-align: center;'>Amrita Manthan</h1>")
58
+ gr.Markdown("<h3 style='text-align: center;'>Preprocessing & Data Mining Portal</h3>")
59
+ gr.Markdown("<p style='text-align: center;'><i>Prof. B. Santhi, SRC, SASTRA</i></p>")
60
+
61
+ with gr.Tabs():
62
+ with gr.TabItem("Step 1: Upload & Process"):
63
+ file_input = gr.File(label="Upload CSV Dataset", file_types=[".csv"])
64
+ process_btn = gr.Button("Analyze Data", variant="primary")
65
+
66
+ with gr.TabItem("Step 2: Data View"):
67
+ with gr.Row():
68
+ out_raw = gr.DataFrame(label="Raw Data (First 10 Rows)")
69
+ out_desc = gr.DataFrame(label="Statistical Summary")
70
+
71
+ with gr.TabItem("Step 3: Visual EDA"):
72
+ out_plot = gr.Image(label="Correlation Heatmap")
73
+
74
+ with gr.TabItem("Step 4: Download Report"):
75
+ gr.Markdown("Click below to download the full preprocessing documentation.")
76
+ out_file = gr.File(label="Download DOCX Report")
77
+
78
+ # Click Logic
79
+ process_btn.click(
80
+ fn=process_data,
81
+ inputs=[file_input],
82
+ outputs=[out_raw, out_desc, out_plot, out_file]
83
+ )
84
+
85
+ demo.launch()