File size: 1,854 Bytes
4088cc4
 
 
 
67b7f64
 
092e617
 
4088cc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
092e617
 
4088cc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
import streamlit as st
from pycaret.classification import setup, compare_models, pull, save_model
import pandas as pd
import os

# Importing necessary modules from pandas_profiling
from pandas_profiling import ProfileReport
from streamlit_pandas_profiling import st_profile_report

def main():
    if os.path.exists('./dataset.csv'):
        df = pd.read_csv('dataset.csv', index_col=None)

    with st.sidebar:
        st.image('https://leilaabdel.com/img/deep_learning_course_pic.png')
        st.title('AutoML Classification')
        choice = st.radio('Navigation', ['Upload', 'EDA', 'Modelling', 'Download'])

    if choice == 'Upload':
        file_uploader_ui()

    elif choice == 'EDA' and 'df' in locals():
        eda_ui(df)

    elif choice == 'Modelling' and 'df' in locals():
        modelling_ui(df)

    elif choice == 'Download':
        download_ui()

def file_uploader_ui():
    st.title('Upload your data file')
    file = st.file_uploader('Upload your data')
    if file:
        df = pd.read_csv(file, index_col=None)
        df.to_csv('dataset.csv', index=None)
        st.dataframe(df.head())

def eda_ui(df):
    st.title('Exploratory Data Analysis')
    profile = ProfileReport(df, explorative=True)
    st_profile_report(profile)

def modelling_ui(df):
    target_col = st.selectbox('Choose the target column', df.columns)
    if st.button('Train model'):
        setup(data=df, target=target_col)
        best_model = compare_models()
        compare_df = pull()
        st.dataframe(compare_df)
        save_model(best_model, 'best_model.pkl')

def download_ui():
    try:
        with open('best_model.pkl', 'rb') as f:
            st.download_button('Download the best model', f, 'best_model.pkl')
    except Exception as e:
        st.error(f"Error downloading the model: {str(e)}")

if __name__ == "__main__":
    main()