Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,147 +1,102 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import cv2
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
if
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
st.
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
"""Applies a transformation and returns the transformed image and description."""
|
| 105 |
-
rows, cols = image.shape[:2]
|
| 106 |
-
|
| 107 |
-
if transform_name == "Translation":
|
| 108 |
-
tx, ty = kwargs["tx"], kwargs["ty"]
|
| 109 |
-
matrix = np.float32([[1, 0, tx], [0, 1, ty]])
|
| 110 |
-
transformed_image = cv2.warpAffine(image, matrix, (cols, rows))
|
| 111 |
-
return cv2.cvtColor(transformed_image, cv2.COLOR_BGR2RGB), f"tx={tx}, ty={ty}"
|
| 112 |
-
|
| 113 |
-
elif transform_name == "Rotation":
|
| 114 |
-
angle = kwargs["angle"]
|
| 115 |
-
center = (cols // 2, rows // 2)
|
| 116 |
-
matrix = cv2.getRotationMatrix2D(center, angle, 1)
|
| 117 |
-
transformed_image = cv2.warpAffine(image, matrix, (cols, rows))
|
| 118 |
-
return cv2.cvtColor(transformed_image, cv2.COLOR_BGR2RGB), f"angle={angle}°"
|
| 119 |
-
|
| 120 |
-
elif transform_name == "Scaling":
|
| 121 |
-
fx, fy = kwargs["fx"], kwargs["fy"]
|
| 122 |
-
transformed_image = cv2.resize(image, None, fx=fx, fy=fy)
|
| 123 |
-
return cv2.cvtColor(transformed_image, cv2.COLOR_BGR2RGB), f"scale_x={fx}, scale_y={fy}"
|
| 124 |
-
|
| 125 |
-
elif transform_name == "Shearing":
|
| 126 |
-
shx, shy = kwargs["shx"], kwargs["shy"]
|
| 127 |
-
matrix = np.float32([[1, shx, 0], [shy, 1, 0]])
|
| 128 |
-
transformed_image = cv2.warpAffine(image, matrix, (cols, rows))
|
| 129 |
-
return cv2.cvtColor(transformed_image, cv2.COLOR_BGR2RGB), f"shear_x={shx}, shear_y={shy}"
|
| 130 |
-
|
| 131 |
-
elif transform_name == "Cropping":
|
| 132 |
-
x_start, x_end, y_start, y_end = kwargs["x_start"], kwargs["x_end"], kwargs["y_start"], kwargs["y_end"]
|
| 133 |
-
cropped_image = image[y_start:y_end, x_start:x_end]
|
| 134 |
-
return cv2.cvtColor(cropped_image, cv2.COLOR_BGR2RGB), f"x=({x_start}, {x_end}), y=({y_start}, {y_end})"
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
def add_to_dataframe(image_name, image, transform_name):
|
| 138 |
-
"""Updates the cumulative DataFrame with a transformed image's details."""
|
| 139 |
-
resized_image = cv2.resize(image, (100, 100)) # Resize for uniformity
|
| 140 |
-
flattened_data = resized_image.flatten()
|
| 141 |
-
new_row = pd.DataFrame([[image_name, transform_name] + flattened_data.tolist()],
|
| 142 |
-
columns=["Image Name", "Transformation"] + [f"Pixel {i}" for i in range(flattened_data.size)])
|
| 143 |
-
st.session_state.combined_data = pd.concat([st.session_state.combined_data, new_row], ignore_index=True)
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
if __name__ == "__main__":
|
| 147 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import seaborn as sns
|
| 6 |
+
from scipy import stats
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="EDA Tool")
|
| 9 |
+
|
| 10 |
+
st.title("Exploratory Data Analysis (EDA) Tool")
|
| 11 |
+
|
| 12 |
+
# File uploader
|
| 13 |
+
uploaded_file = st.file_uploader("Upload a CSV or Excel file", type=["csv", "xlsx"])
|
| 14 |
+
|
| 15 |
+
if uploaded_file:
|
| 16 |
+
# Load dataset
|
| 17 |
+
file_extension = uploaded_file.name.split(".")[-1]
|
| 18 |
+
if file_extension == "csv":
|
| 19 |
+
df = pd.read_csv(uploaded_file)
|
| 20 |
+
else:
|
| 21 |
+
df = pd.read_excel(uploaded_file)
|
| 22 |
+
|
| 23 |
+
st.write("### Preview of the Dataset")
|
| 24 |
+
st.write(df.head())
|
| 25 |
+
|
| 26 |
+
# Dataset Information
|
| 27 |
+
st.write("### Dataset Info")
|
| 28 |
+
st.write(f"Rows: {df.shape[0]}, Columns: {df.shape[1]}")
|
| 29 |
+
|
| 30 |
+
st.write("### Data Types")
|
| 31 |
+
st.write(df.dtypes)
|
| 32 |
+
|
| 33 |
+
st.write("### Missing Values")
|
| 34 |
+
st.write(df.isnull().sum())
|
| 35 |
+
|
| 36 |
+
# Summary Statistics
|
| 37 |
+
st.write("### Summary Statistics")
|
| 38 |
+
st.write(df.describe())
|
| 39 |
+
|
| 40 |
+
# Correlation Heatmap
|
| 41 |
+
st.write("### Correlation Heatmap")
|
| 42 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 43 |
+
sns.heatmap(df.corr(), annot=True, cmap="coolwarm", fmt=".2f", linewidths=0.5)
|
| 44 |
+
st.pyplot(fig)
|
| 45 |
+
|
| 46 |
+
# Pairplot
|
| 47 |
+
st.write("### Pairplot")
|
| 48 |
+
if len(df.columns) <= 5: # Avoid plotting for too many columns
|
| 49 |
+
fig = sns.pairplot(df)
|
| 50 |
+
st.pyplot(fig)
|
| 51 |
+
else:
|
| 52 |
+
st.write("Too many columns for pairplot, showing only first 5 numerical columns.")
|
| 53 |
+
fig = sns.pairplot(df.iloc[:, :5])
|
| 54 |
+
st.pyplot(fig)
|
| 55 |
+
|
| 56 |
+
# Univariate Analysis
|
| 57 |
+
st.write("### Univariate Analysis")
|
| 58 |
+
for column in df.select_dtypes(include=[np.number]).columns:
|
| 59 |
+
st.write(f"#### {column}")
|
| 60 |
+
fig, ax = plt.subplots()
|
| 61 |
+
sns.histplot(df[column].dropna(), kde=True, bins=30, ax=ax)
|
| 62 |
+
st.pyplot(fig)
|
| 63 |
+
fig, ax = plt.subplots()
|
| 64 |
+
sns.boxplot(x=df[column], ax=ax)
|
| 65 |
+
st.pyplot(fig)
|
| 66 |
+
|
| 67 |
+
# Bivariate Analysis
|
| 68 |
+
st.write("### Bivariate Analysis")
|
| 69 |
+
numeric_cols = df.select_dtypes(include=[np.number]).columns.tolist()
|
| 70 |
+
if len(numeric_cols) >= 2:
|
| 71 |
+
col1, col2 = st.selectbox("Select two columns for scatter plot", numeric_cols, index=[0, 1])
|
| 72 |
+
fig, ax = plt.subplots()
|
| 73 |
+
sns.scatterplot(x=df[col1], y=df[col2], ax=ax)
|
| 74 |
+
st.pyplot(fig)
|
| 75 |
+
|
| 76 |
+
# Regression Plot
|
| 77 |
+
fig, ax = plt.subplots()
|
| 78 |
+
sns.regplot(x=df[col1], y=df[col2], ax=ax)
|
| 79 |
+
st.pyplot(fig)
|
| 80 |
+
|
| 81 |
+
# Correlation
|
| 82 |
+
correlation = df[col1].corr(df[col2])
|
| 83 |
+
st.write(f"Correlation between {col1} and {col2}: {correlation:.4f}")
|
| 84 |
+
|
| 85 |
+
# Statistical Tests
|
| 86 |
+
st.write("### Statistical Tests")
|
| 87 |
+
if len(numeric_cols) >= 2:
|
| 88 |
+
col1, col2 = st.selectbox("Select two columns for t-test", numeric_cols, index=[0, 1])
|
| 89 |
+
t_stat, p_value = stats.ttest_ind(df[col1].dropna(), df[col2].dropna())
|
| 90 |
+
st.write(f"T-Test between {col1} and {col2}: T-Statistic = {t_stat:.4f}, P-Value = {p_value:.4f}")
|
| 91 |
+
|
| 92 |
+
# Outliers Detection
|
| 93 |
+
st.write("### Outliers Detection")
|
| 94 |
+
selected_col = st.selectbox("Select a column for outlier detection", numeric_cols)
|
| 95 |
+
Q1 = df[selected_col].quantile(0.25)
|
| 96 |
+
Q3 = df[selected_col].quantile(0.75)
|
| 97 |
+
IQR = Q3 - Q1
|
| 98 |
+
outliers = df[(df[selected_col] < (Q1 - 1.5 * IQR)) | (df[selected_col] > (Q3 + 1.5 * IQR))]
|
| 99 |
+
st.write(f"Number of outliers in {selected_col}: {outliers.shape[0]}")
|
| 100 |
+
st.write(outliers)
|
| 101 |
+
|
| 102 |
+
st.write("### EDA Complete")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|