Ashar086 commited on
Commit
47cec27
·
verified ·
1 Parent(s): 100c933

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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.")