Upload 2 files
Browse files- app.py +45 -0
- requirements.txt.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def analyze_csv(file_obj):
|
| 5 |
+
# 1. Read the uploaded CSV
|
| 6 |
+
df = pd.read_csv(file_obj.name)
|
| 7 |
+
|
| 8 |
+
# 2. Extract basic shape
|
| 9 |
+
row_count = len(df)
|
| 10 |
+
col_count = len(df.columns)
|
| 11 |
+
|
| 12 |
+
# 3. Automatically calculate statistics (mean, min, max) and round to 2 decimals
|
| 13 |
+
summary_stats = df.describe().round(2)
|
| 14 |
+
|
| 15 |
+
# 4. Grab the first 5 rows for a preview
|
| 16 |
+
head_df = df.head()
|
| 17 |
+
|
| 18 |
+
# 5. Format the text report
|
| 19 |
+
report = f"### 📌 Data Overview\n* **Total Rows:** {row_count}\n* **Total Columns:** {col_count}\n\n"
|
| 20 |
+
report += "The tool has automatically processed the mathematical summary and extracted a data preview below."
|
| 21 |
+
|
| 22 |
+
return report, summary_stats, head_df
|
| 23 |
+
|
| 24 |
+
# Building the modern UI
|
| 25 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 26 |
+
gr.Markdown("# 📊 Automated Business Data Analyzer")
|
| 27 |
+
gr.Markdown("Upload any raw CSV file to instantly generate a statistical breakdown.")
|
| 28 |
+
|
| 29 |
+
with gr.Row():
|
| 30 |
+
file_input = gr.File(label="Upload CSV File here", file_types=[".csv"])
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
text_output = gr.Markdown()
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
stats_output = gr.Dataframe(label="Mathematical Summary (Averages, Min, Max)")
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
head_output = gr.Dataframe(label="Raw Data Preview (First 5 Rows)")
|
| 40 |
+
|
| 41 |
+
# Connect the upload button to the logic function
|
| 42 |
+
file_input.upload(fn=analyze_csv, inputs=file_input, outputs=[text_output, stats_output, head_output])
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
demo.launch()
|
requirements.txt.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
gradio
|