Ashar086 commited on
Commit
f158d04
·
verified ·
1 Parent(s): 8ce9f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -38
app.py CHANGED
@@ -4,61 +4,98 @@ from data_processor import DataProcessor
4
  from visualizer import Visualizer
5
  from analyzer import Analyzer
6
  from openai_agent import OpenAIAgent
 
 
 
 
 
7
 
8
- st.set_page_config(page_title="AI-Powered Data Viz", layout="wide")
9
 
10
- st.title("AI-Powered Data Visualization")
11
 
12
  # File uploader
13
- uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
14
 
15
  if uploaded_file is not None:
16
- # Read the CSV file
17
- df = pd.read_csv(uploaded_file)
18
 
19
- # Initialize our components
20
  data_processor = DataProcessor(df)
21
  visualizer = Visualizer()
22
  analyzer = Analyzer()
23
  openai_agent = OpenAIAgent()
 
 
 
 
24
 
25
- # Data Cleaning and Preprocessing
26
- st.header("Data Cleaning and Preprocessing")
27
- st.write("Original data shape:", df.shape)
28
- st.write("Columns with missing values:", data_processor.get_columns_with_missing_values())
29
-
30
- if st.button("Clean Data"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  df_cleaned = data_processor.clean_data()
32
  st.write("Cleaned data shape:", df_cleaned.shape)
33
  st.write(df_cleaned.head())
 
 
 
 
34
 
35
- # Data Visualization
36
- st.header("Data Visualization")
37
- columns = df.columns.tolist()
38
- x_axis = st.selectbox("Select X-axis", columns)
39
- y_axis = st.selectbox("Select Y-axis", columns)
40
-
41
- chart_type = st.radio("Select chart type", ["Scatter", "Line", "Bar"])
42
-
43
- if st.button("Generate Visualization"):
44
- fig = visualizer.create_plot(df, x_axis, y_axis, chart_type)
45
- st.plotly_chart(fig)
46
 
47
- # Data Analysis
48
- st.header("Data Analysis")
49
- analysis_prompt = st.text_input("Enter your analysis question:")
50
-
51
- if st.button("Analyze"):
52
- analysis_result = analyzer.analyze_data(df, analysis_prompt)
53
- st.write(analysis_result)
54
 
55
- # OpenAI Integration
56
- st.header("AI-Powered Insights")
57
- ai_prompt = st.text_area("Ask the AI for insights:")
58
-
59
- if st.button("Get AI Insights"):
60
- ai_response = openai_agent.get_insights(df, ai_prompt)
61
- st.write(ai_response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  else:
64
- st.write("Please upload a CSV file to get started.")
 
 
 
 
 
4
  from visualizer import Visualizer
5
  from analyzer import Analyzer
6
  from openai_agent import OpenAIAgent
7
+ from time_series_analyzer import TimeSeriesAnalyzer
8
+ from machine_learning import MachineLearning
9
+ from text_analyzer import TextAnalyzer
10
+ from geospatial_analyzer import GeospatialAnalyzer
11
+ from utils import load_data, save_data
12
 
13
+ st.set_page_config(page_title="AI-Powered Data Analysis", layout="wide")
14
 
15
+ st.title("AI-Powered Data Analysis and Visualization")
16
 
17
  # File uploader
18
+ uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type="csv")
19
 
20
  if uploaded_file is not None:
21
+ df = load_data(uploaded_file)
 
22
 
23
+ # Initialize components
24
  data_processor = DataProcessor(df)
25
  visualizer = Visualizer()
26
  analyzer = Analyzer()
27
  openai_agent = OpenAIAgent()
28
+ time_series_analyzer = TimeSeriesAnalyzer()
29
+ ml = MachineLearning()
30
+ text_analyzer = TextAnalyzer()
31
+ geo_analyzer = GeospatialAnalyzer()
32
 
33
+ # Sidebar for feature selection
34
+ feature = st.sidebar.radio(
35
+ "Select a feature",
36
+ ["Data Overview", "Data Cleaning", "Data Visualization", "Data Analysis",
37
+ "AI Insights", "Time Series Analysis", "Machine Learning",
38
+ "Text Analysis", "Geospatial Analysis", "Custom AI Tasks"]
39
+ )
40
+
41
+ if feature == "Data Overview":
42
+ st.header("Data Overview")
43
+ st.write("Dataset shape:", df.shape)
44
+ st.write("Columns:", df.columns.tolist())
45
+ st.write("Sample data:")
46
+ st.write(df.head())
47
+
48
+ if st.checkbox("Show data types"):
49
+ st.write(df.dtypes)
50
+
51
+ if st.checkbox("Show summary statistics"):
52
+ st.write(df.describe())
53
+
54
+ elif feature == "Data Cleaning":
55
+ st.header("Data Cleaning and Preprocessing")
56
  df_cleaned = data_processor.clean_data()
57
  st.write("Cleaned data shape:", df_cleaned.shape)
58
  st.write(df_cleaned.head())
59
+
60
+ if st.button("Save Cleaned Data"):
61
+ save_data(df_cleaned, "cleaned_data.csv")
62
+ st.success("Cleaned data saved successfully!")
63
 
64
+ elif feature == "Data Visualization":
65
+ st.header("Data Visualization")
66
+ visualizer.create_visualizations(df)
 
 
 
 
 
 
 
 
67
 
68
+ elif feature == "Data Analysis":
69
+ st.header("Data Analysis")
70
+ analyzer.perform_analysis(df)
 
 
 
 
71
 
72
+ elif feature == "AI Insights":
73
+ st.header("AI-Powered Insights")
74
+ openai_agent.generate_insights(df)
75
+
76
+ elif feature == "Time Series Analysis":
77
+ st.header("Time Series Analysis")
78
+ time_series_analyzer.analyze(df)
79
+
80
+ elif feature == "Machine Learning":
81
+ st.header("Machine Learning")
82
+ ml.perform_ml_tasks(df)
83
+
84
+ elif feature == "Text Analysis":
85
+ st.header("Text Analysis")
86
+ text_analyzer.analyze_text(df)
87
+
88
+ elif feature == "Geospatial Analysis":
89
+ st.header("Geospatial Analysis")
90
+ geo_analyzer.analyze_geospatial_data(df)
91
+
92
+ elif feature == "Custom AI Tasks":
93
+ st.header("Custom AI Tasks")
94
+ openai_agent.custom_ai_task(df)
95
 
96
  else:
97
+ st.write("Please upload a CSV file to get started.")
98
+
99
+ # Add a footer
100
+ st.sidebar.markdown("---")
101
+ st.sidebar.info("Developed by Your Company Name")