Ashar086 commited on
Commit
79bdb89
·
verified ·
1 Parent(s): 46b0849

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +119 -99
app.py CHANGED
@@ -1,101 +1,121 @@
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import pandas as pd
3
- from data_processor import DataProcessor
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")
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from data_cleaning import DataCleaner
3
+ from visualization import VisualizationSelector
4
+ from data_analysis import DataAnalyzer
5
+ from report_generator import ReportGenerator
6
+ from api_integration import APIConnector
7
+ from natural_language_query import NLQueryEngine
8
+ from predictive_analytics import PredictiveAnalytics
9
+ from anomaly_detection import AnomalyDetector
10
+ from time_series_forecasting import TimeSeriesForecaster
11
+ from geospatial_visualization import GeospatialVisualizer
12
+ from sentiment_analysis import SentimentAnalyzer
13
+ from data_storytelling import DataStoryteller
14
+ from data_privacy import DataPrivacyTool
15
  import pandas as pd
16
+
17
+ class DataAutomationApp:
18
+ def __init__(self):
19
+ self.data = None
20
+ self.cleaner = DataCleaner()
21
+ self.visualizer = VisualizationSelector()
22
+ self.analyzer = DataAnalyzer()
23
+ self.report_generator = ReportGenerator()
24
+ self.api_connector = APIConnector()
25
+ self.nl_query_engine = NLQueryEngine()
26
+ self.predictive_analytics = PredictiveAnalytics()
27
+ self.anomaly_detector = AnomalyDetector()
28
+ self.time_series_forecaster = TimeSeriesForecaster()
29
+ self.geospatial_visualizer = GeospatialVisualizer()
30
+ self.sentiment_analyzer = SentimentAnalyzer()
31
+ self.data_storyteller = DataStoryteller()
32
+ self.data_privacy_tool = DataPrivacyTool()
33
+
34
+ def load_data(self, file):
35
+ if file.name.endswith('.csv'):
36
+ self.data = pd.read_csv(file)
37
+ elif file.name.endswith(('.xls', '.xlsx')):
38
+ self.data = pd.read_excel(file)
39
+ else:
40
+ st.error("Unsupported file format. Please upload a CSV or Excel file.")
41
+
42
+ def run(self):
43
+ st.title("Data Automation and Visualization App")
44
+
45
+ # File upload
46
+ uploaded_file = st.file_uploader("Choose a CSV or Excel file", type=["csv", "xlsx"])
47
+ if uploaded_file is not None:
48
+ self.load_data(uploaded_file)
49
+ if self.data is not None:
50
+ st.success("Data loaded successfully!")
51
+
52
+ # Data cleaning
53
+ if st.button("Clean Data"):
54
+ self.data = self.cleaner.clean(self.data)
55
+ st.write(self.data.head())
56
+
57
+ # Visualization
58
+ if st.button("Generate Visualizations"):
59
+ visualizations = self.visualizer.select_visualizations(self.data)
60
+ for viz in visualizations:
61
+ st.pyplot(viz)
62
+
63
+ # Data Analysis
64
+ if st.button("Analyze Data"):
65
+ insights = self.analyzer.analyze(self.data)
66
+ st.write(insights)
67
+
68
+ # Natural Language Query
69
+ query = st.text_input("Ask a question about your data:")
70
+ if query:
71
+ result = self.nl_query_engine.process_query(query, self.data)
72
+ st.write(result)
73
+
74
+ # Predictive Analytics
75
+ if st.button("Run Predictive Analytics"):
76
+ prediction = self.predictive_analytics.predict(self.data)
77
+ st.write(prediction)
78
+
79
+ # Anomaly Detection
80
+ if st.button("Detect Anomalies"):
81
+ anomalies = self.anomaly_detector.detect(self.data)
82
+ st.write(anomalies)
83
+
84
+ # Time Series Forecasting
85
+ if st.button("Forecast Time Series"):
86
+ forecast = self.time_series_forecaster.forecast(self.data)
87
+ st.write(forecast)
88
+
89
+ # Geospatial Visualization
90
+ if st.button("Geospatial Visualization"):
91
+ geo_viz = self.geospatial_visualizer.visualize(self.data)
92
+ st.pyplot(geo_viz)
93
+
94
+ # Sentiment Analysis
95
+ if st.button("Analyze Sentiment"):
96
+ sentiment = self.sentiment_analyzer.analyze(self.data)
97
+ st.write(sentiment)
98
+
99
+ # Data Storytelling
100
+ if st.button("Generate Data Story"):
101
+ story = self.data_storyteller.generate_story(self.data)
102
+ st.write(story)
103
+
104
+ # Data Privacy Check
105
+ if st.button("Check Data Privacy"):
106
+ privacy_report = self.data_privacy_tool.check_privacy(self.data)
107
+ st.write(privacy_report)
108
+
109
+ # Report Generation
110
+ if st.button("Generate Report"):
111
+ report = self.report_generator.generate(self.data)
112
+ st.download_button(
113
+ label="Download Report",
114
+ data=report,
115
+ file_name="data_report.txt",
116
+ mime="text/plain"
117
+ )
118
+
119
+ if __name__ == "__main__":
120
+ app = DataAutomationApp()
121
+ app.run()