Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
import matplotlib.pyplot as plt
|
| 4 |
-
import io
|
| 5 |
from sklearn.model_selection import train_test_split
|
| 6 |
from sklearn.preprocessing import LabelEncoder
|
| 7 |
from sklearn.ensemble import RandomForestClassifier
|
|
@@ -12,6 +10,7 @@ from sklearn.tree import DecisionTreeClassifier
|
|
| 12 |
from sklearn.naive_bayes import GaussianNB
|
| 13 |
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
|
| 14 |
from tabulate import tabulate
|
|
|
|
| 15 |
|
| 16 |
# Function to convert DataFrame to Excel format
|
| 17 |
def to_excel(df):
|
|
@@ -21,25 +20,6 @@ def to_excel(df):
|
|
| 21 |
output.seek(0)
|
| 22 |
return output
|
| 23 |
|
| 24 |
-
# Function to save table as PNG
|
| 25 |
-
def save_table_as_png(df):
|
| 26 |
-
fig, ax = plt.subplots(figsize=(8, 6))
|
| 27 |
-
ax.axis('tight')
|
| 28 |
-
ax.axis('off')
|
| 29 |
-
|
| 30 |
-
# Create a table from the DataFrame
|
| 31 |
-
table = ax.table(cellText=df.values, colLabels=df.columns, loc='center', cellLoc='center')
|
| 32 |
-
table.auto_set_font_size(False)
|
| 33 |
-
table.set_fontsize(10)
|
| 34 |
-
table.scale(1.2, 1.2)
|
| 35 |
-
|
| 36 |
-
# Save the table as a PNG image
|
| 37 |
-
img_path = "/tmp/model_report.png"
|
| 38 |
-
plt.savefig(img_path, format="png", bbox_inches="tight")
|
| 39 |
-
plt.close(fig)
|
| 40 |
-
|
| 41 |
-
return img_path
|
| 42 |
-
|
| 43 |
# File uploader
|
| 44 |
st.title("Model Training with Metrics")
|
| 45 |
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
|
@@ -130,7 +110,7 @@ if uploaded_file is not None:
|
|
| 130 |
|
| 131 |
# Option to download the model performance metrics (Results Table)
|
| 132 |
st.download_button(
|
| 133 |
-
label="Download Model Report
|
| 134 |
data=to_excel(metrics_df), # The metrics dataframe
|
| 135 |
file_name="model_report.xlsx",
|
| 136 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
@@ -138,18 +118,8 @@ if uploaded_file is not None:
|
|
| 138 |
|
| 139 |
# Option to download the cleaned dataset
|
| 140 |
st.download_button(
|
| 141 |
-
label="Download Cleaned Dataset
|
| 142 |
data=to_excel(df), # The cleaned dataset is 'df'
|
| 143 |
file_name="cleaned_dataset.xlsx",
|
| 144 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 145 |
)
|
| 146 |
-
|
| 147 |
-
# Option to download the report as PNG
|
| 148 |
-
img_path = save_table_as_png(metrics_df)
|
| 149 |
-
with open(img_path, "rb") as file:
|
| 150 |
-
st.download_button(
|
| 151 |
-
label="Download Model Report (PNG)",
|
| 152 |
-
data=file,
|
| 153 |
-
file_name="model_report.png",
|
| 154 |
-
mime="image/png"
|
| 155 |
-
)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
|
|
|
| 3 |
from sklearn.model_selection import train_test_split
|
| 4 |
from sklearn.preprocessing import LabelEncoder
|
| 5 |
from sklearn.ensemble import RandomForestClassifier
|
|
|
|
| 10 |
from sklearn.naive_bayes import GaussianNB
|
| 11 |
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
|
| 12 |
from tabulate import tabulate
|
| 13 |
+
import io
|
| 14 |
|
| 15 |
# Function to convert DataFrame to Excel format
|
| 16 |
def to_excel(df):
|
|
|
|
| 20 |
output.seek(0)
|
| 21 |
return output
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# File uploader
|
| 24 |
st.title("Model Training with Metrics")
|
| 25 |
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
|
|
|
| 110 |
|
| 111 |
# Option to download the model performance metrics (Results Table)
|
| 112 |
st.download_button(
|
| 113 |
+
label="Download Model Report",
|
| 114 |
data=to_excel(metrics_df), # The metrics dataframe
|
| 115 |
file_name="model_report.xlsx",
|
| 116 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
|
| 118 |
|
| 119 |
# Option to download the cleaned dataset
|
| 120 |
st.download_button(
|
| 121 |
+
label="Download Cleaned Dataset",
|
| 122 |
data=to_excel(df), # The cleaned dataset is 'df'
|
| 123 |
file_name="cleaned_dataset.xlsx",
|
| 124 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 125 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|