Arif commited on
Commit
9f22029
Β·
1 Parent(s): ca37c17

Updated app.py to v12

Browse files
Files changed (1) hide show
  1. app.py +47 -15
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
 
4
  # Page configuration
5
  st.set_page_config(
@@ -48,20 +49,39 @@ tab1, tab2, tab3 = st.tabs(["πŸ“€ Upload & Analyze", "πŸ’¬ Chat", "πŸ“Š About"])
48
  with tab1:
49
  st.header("πŸ“€ Upload and Analyze Data")
50
 
 
 
51
  uploaded_file = st.file_uploader(
52
  "Upload a CSV or Excel file",
53
  type=["csv", "xlsx", "xls"],
54
- help="Supported formats: CSV, Excel"
55
  )
56
 
57
  if uploaded_file is not None:
58
- st.success(f"βœ… File uploaded: {uploaded_file.name}")
59
-
60
  try:
61
- if uploaded_file.name.endswith('.csv'):
62
- df = pd.read_csv(uploaded_file)
63
- else:
64
- df = pd.read_excel(uploaded_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  # Display data preview
67
  st.subheader("πŸ“‹ Data Preview")
@@ -76,10 +96,17 @@ with tab1:
76
  with col2:
77
  st.metric("Columns", df.shape[1])
78
  with col3:
79
- st.metric("Memory", f"{df.memory_usage(deep=True).sum() / 1024:.2f} KB")
 
 
 
 
80
 
81
  # Detailed statistics
82
- st.write(df.describe().T)
 
 
 
83
 
84
  # Ask AI about the data
85
  st.subheader("❓ Ask AI About Your Data")
@@ -95,7 +122,8 @@ with tab1:
95
  st.write(response)
96
 
97
  except Exception as e:
98
- st.error(f"Error reading file: {e}")
 
99
 
100
  # ============================================================================
101
  # TAB 2: Chat
@@ -174,12 +202,16 @@ with tab3:
174
  - [Streamlit](https://streamlit.io/) - Web framework
175
  - [Pandas](https://pandas.pydata.org/) - Data analysis
176
 
177
- ### πŸ“– Quick Tips
 
 
 
 
 
178
 
179
- - Upload CSV or Excel files
180
- - View data preview and statistics
181
- - Ask specific questions about your data
182
- - Questions about averages, trends, outliers work best
183
 
184
  ### πŸ”— Links
185
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import os
4
 
5
  # Page configuration
6
  st.set_page_config(
 
49
  with tab1:
50
  st.header("πŸ“€ Upload and Analyze Data")
51
 
52
+ st.info("πŸ’‘ Tip: For best results, use smaller files (< 10MB). Try CSV format if Excel gives issues.")
53
+
54
  uploaded_file = st.file_uploader(
55
  "Upload a CSV or Excel file",
56
  type=["csv", "xlsx", "xls"],
57
+ help="Supported formats: CSV, Excel (Max 200MB)"
58
  )
59
 
60
  if uploaded_file is not None:
 
 
61
  try:
62
+ # Check file size
63
+ file_size = uploaded_file.size / (1024 * 1024) # Convert to MB
64
+
65
+ if file_size > 100:
66
+ st.warning(f"⚠️ File is {file_size:.2f}MB. Large files may take longer to process.")
67
+
68
+ st.success(f"βœ… File uploaded: {uploaded_file.name} ({file_size:.2f}MB)")
69
+
70
+ # Read file with error handling
71
+ try:
72
+ if uploaded_file.name.endswith('.csv'):
73
+ df = pd.read_csv(uploaded_file, on_bad_lines='skip')
74
+ else:
75
+ df = pd.read_excel(uploaded_file, engine='openpyxl')
76
+ except Exception as read_error:
77
+ st.error(f"❌ Error reading file. Try converting to CSV first.")
78
+ st.info(f"Details: {str(read_error)[:100]}")
79
+ st.stop()
80
+
81
+ # Validate dataframe
82
+ if df.empty:
83
+ st.error("❌ File is empty or has no readable data.")
84
+ st.stop()
85
 
86
  # Display data preview
87
  st.subheader("πŸ“‹ Data Preview")
 
96
  with col2:
97
  st.metric("Columns", df.shape[1])
98
  with col3:
99
+ try:
100
+ memory = df.memory_usage(deep=True).sum() / 1024
101
+ st.metric("Memory", f"{memory:.2f} KB")
102
+ except:
103
+ st.metric("Memory", "N/A")
104
 
105
  # Detailed statistics
106
+ try:
107
+ st.write(df.describe().T)
108
+ except:
109
+ st.info("Could not generate statistics for this data.")
110
 
111
  # Ask AI about the data
112
  st.subheader("❓ Ask AI About Your Data")
 
122
  st.write(response)
123
 
124
  except Exception as e:
125
+ st.error(f"❌ Error processing file: {str(e)[:100]}")
126
+ st.info("Try uploading a smaller file or converting to CSV format.")
127
 
128
  # ============================================================================
129
  # TAB 2: Chat
 
202
  - [Streamlit](https://streamlit.io/) - Web framework
203
  - [Pandas](https://pandas.pydata.org/) - Data analysis
204
 
205
+ ### πŸ“– Troubleshooting
206
+
207
+ **File upload fails?**
208
+ - Try converting Excel to CSV first
209
+ - Use smaller files (< 10MB)
210
+ - Check file format is valid
211
 
212
+ **Data preview is empty?**
213
+ - File may be corrupted
214
+ - Try opening in Excel and resaving as CSV
 
215
 
216
  ### πŸ”— Links
217