destiratnakomala commited on
Commit
7a5117d
·
verified ·
1 Parent(s): 5937a13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -11
app.py CHANGED
@@ -17,17 +17,35 @@ def main():
17
  st.title("Machine Learning")
18
 
19
  with st.expander("1: Add Your Data Source"):
20
- uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
21
-
22
- # If no file is uploaded, load example.csv
23
- if uploaded_file is None:
24
- try:
25
- data = pd.read_csv('example.csv') # Load example CSV
26
- st.info("Loaded example.csv")
27
- except FileNotFoundError:
28
- st.error("Example CSV file not found. Please upload your own CSV file.")
29
- else:
30
- data = pd.read_csv(uploaded_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  with st.expander("2: DataSet Preview"):
33
  if uploaded_file is not None:
 
17
  st.title("Machine Learning")
18
 
19
  with st.expander("1: Add Your Data Source"):
20
+ uploaded_file = st.file_uploader("Upload your CSV or Excel file", type=["csv", "xlsx", "xls"])
21
+
22
+ if uploaded_file is None:
23
+ try:
24
+ data = pd.read_csv('example.csv') # Load example CSV
25
+ st.info("Loaded example.csv")
26
+ except FileNotFoundError:
27
+ st.error("Example CSV file not found. Please upload your own CSV or Excel file.")
28
+ except pd.errors.EmptyDataError:
29
+ st.error("Example CSV file is empty or invalid.")
30
+ else:
31
+ try:
32
+ if uploaded_file.name.endswith('.csv'):
33
+ data = pd.read_csv(uploaded_file)
34
+ elif uploaded_file.name.endswith(('.xlsx', '.xls')):
35
+ data = pd.read_excel(uploaded_file)
36
+
37
+ # Check if the file has content
38
+ if data.empty:
39
+ st.error("Uploaded file is empty. Please upload a valid CSV or Excel file.")
40
+ else:
41
+ st.success("File uploaded successfully!")
42
+ except pd.errors.EmptyDataError:
43
+ st.error("The uploaded file is empty or contains no readable data.")
44
+ except ValueError:
45
+ st.error("Error in file format. Please ensure the file is a valid CSV or Excel.")
46
+ except Exception as e:
47
+ st.error(f"An error occurred: {e}")
48
+
49
 
50
  with st.expander("2: DataSet Preview"):
51
  if uploaded_file is not None: