Spaces:
Sleeping
Sleeping
File size: 4,859 Bytes
9183c57 e935e51 9183c57 e935e51 9183c57 |
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 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
import time
import streamlit as st
from streamlit_lottie import st_lottie
from util import load_lottie, stream_data, welcome_message, introduction_message
from prediction_model import prediction_model_pipeline
from cluster_model import cluster_model_pipeline
from regression_model import regression_model_pipeline
from visualization import data_visualization
from src.util import read_file_from_streamlit
st.set_page_config(page_title="Streamline Analyst", page_icon=":rocket:", layout="wide")
# TITLE SECTION
with st.container():
st.subheader("Hello there 👋")
st.title("Welcome to Streamline Analyst!")
if 'initialized' not in st.session_state:
st.session_state.initialized = True
if st.session_state.initialized:
st.session_state.welcome_message = welcome_message()
st.write(stream_data(st.session_state.welcome_message))
time.sleep(0.5)
st.caption("There is a demo vedio on GitHub")
st.write("[Github > ](https://github.com/Wilson-ZheLin/Streamline-Analyst)")
st.session_state.initialized = False
else:
st.write(st.session_state.welcome_message)
st.caption("There is a demo vedio on GitHub")
st.write("[Github > ](https://github.com/Wilson-ZheLin/Streamline-Analyst)")
# INTRO SECTION
with st.container():
st.divider()
if 'lottie' not in st.session_state:
st.session_state.lottie_url1, st.session_state.lottie_url2 = load_lottie()
st.session_state.lottie = True
left_column_r1, right_column_r1 = st.columns([6, 4])
with left_column_r1:
st.header("What can Streamline Analyst do?")
st.write(introduction_message()[0])
with right_column_r1:
if st.session_state.lottie:
st_lottie(st.session_state.lottie_url1, height=280, key="animation1")
left_column_r2, _, right_column_r2 = st.columns([6, 1, 5])
with left_column_r2:
if st.session_state.lottie:
st_lottie(st.session_state.lottie_url2, height=200, key="animation2")
with right_column_r2:
st.header("Simple to Use")
st.write(introduction_message()[1])
# MAIN SECTION
with st.container():
st.divider()
st.header("Let's Get Started")
left_column, right_column = st.columns([6, 4])
with left_column:
API_KEY = st.text_input(
"Your API Key won't be stored or shared!",
placeholder="Enter your API key here...",
)
st.write("👆Your OpenAI API key:")
uploaded_file = st.file_uploader("Choose a data file. Your data won't be stored as well!", accept_multiple_files=False, type=['csv', 'json', 'xls', 'xlsx'])
if uploaded_file:
if uploaded_file.getvalue():
uploaded_file.seek(0)
st.session_state.DF_uploaded = read_file_from_streamlit(uploaded_file)
st.session_state.is_file_empty = False
else:
st.session_state.is_file_empty = True
with right_column:
SELECTED_MODEL = st.selectbox(
'Which OpenAI model do you want to use?',
('GPT-4-Turbo', 'GPT-3.5-Turbo'))
MODE = st.selectbox(
'Select proper data analysis mode',
('Predictive Classification', 'Clustering Model', 'Regression Model', 'Data Visualization'))
st.write(f'Model selected: :green[{SELECTED_MODEL}]')
st.write(f'Data analysis mode: :green[{MODE}]')
# Proceed Button
is_proceed_enabled = uploaded_file is not None and API_KEY != "" or uploaded_file is not None and MODE == "Data Visualization"
# Initialize the 'button_clicked' state
if 'button_clicked' not in st.session_state:
st.session_state.button_clicked = False
if st.button('Start Analysis', disabled=(not is_proceed_enabled) or st.session_state.button_clicked, type="primary"):
st.session_state.button_clicked = True
if "is_file_empty" in st.session_state and st.session_state.is_file_empty:
st.caption('Your data file is empty!')
# Start Analysis
if st.session_state.button_clicked:
GPT_MODEL = 4 if SELECTED_MODEL == 'GPT-4-Turbo' else 3.5
with st.container():
if "DF_uploaded" not in st.session_state:
st.error("File is empty!")
else:
if MODE == 'Predictive Classification':
prediction_model_pipeline(st.session_state.DF_uploaded, API_KEY, GPT_MODEL)
elif MODE == 'Clustering Model':
cluster_model_pipeline(st.session_state.DF_uploaded, API_KEY, GPT_MODEL)
elif MODE == 'Regression Model':
regression_model_pipeline(st.session_state.DF_uploaded, API_KEY, GPT_MODEL)
elif MODE == 'Data Visualization':
data_visualization(st.session_state.DF_uploaded) |