alexacido commited on
Commit
c1cefb8
verified
1 Parent(s): 9188866

Upload 4 files

Browse files
Files changed (2) hide show
  1. app.py +89 -95
  2. requirements.txt +4 -5
app.py CHANGED
@@ -1,95 +1,89 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import google.generativeai as genai
4
- import matplotlib.pyplot as plt
5
- import seaborn as sns
6
- import plotly.express as px
7
-
8
- # Set up page layout
9
- st.set_page_config(page_title="AI CSV Data Analyst", layout="wide")
10
-
11
- # Initialize Gemini API (Replace with your API Key)
12
- GEMINI_API_KEY = "AIzaSyDt0TM6beHrE-f5bvfYXQa6iDACSCfU7go"
13
- genai.configure(api_key=GEMINI_API_KEY)
14
-
15
- # Create two columns (70:30 split)
16
- left_col, right_col = st.columns([7, 3])
17
-
18
- with left_col:
19
- st.title("馃搳 AI-Powered CSV Data Analyst")
20
-
21
- # File Upload
22
- uploaded_file = st.file_uploader("Upload a CSV or Excel file", type=["csv", "xlsx"])
23
-
24
- if uploaded_file is not None:
25
- # Read File
26
- file_ext = uploaded_file.name.split(".")[-1]
27
- if file_ext == "csv":
28
- df = pd.read_csv(uploaded_file)
29
- elif file_ext == "xlsx":
30
- df = pd.read_excel(uploaded_file, engine="openpyxl")
31
-
32
- # Display the DataFrame
33
- st.subheader("馃搨 Uploaded Data")
34
- st.dataframe(df)
35
-
36
- # Data Insights
37
- st.subheader("馃搱 Data Insights")
38
-
39
- # Dataset Summary
40
- st.write(f"**Rows:** {df.shape[0]}, **Columns:** {df.shape[1]}")
41
- st.write(f"**Missing Values:**")
42
- st.write(df.isnull().sum())
43
-
44
- # Basic Statistics
45
- st.subheader("馃搳 Statistical Summary")
46
- st.write(df.describe())
47
-
48
- # Visualizations
49
- st.subheader("馃搲 Data Visualizations")
50
-
51
- # Select Column for Histogram
52
- numeric_columns = df.select_dtypes(include=["number"]).columns
53
- if len(numeric_columns) > 0:
54
- col = st.selectbox("Select a column for histogram:", numeric_columns)
55
- fig = px.histogram(df, x=col, title=f"Histogram of {col}")
56
- st.plotly_chart(fig)
57
-
58
- # Correlation Heatmap
59
- if len(numeric_columns) > 1:
60
- st.subheader("馃攳 Correlation Heatmap")
61
- fig, ax = plt.subplots(figsize=(6, 4))
62
- sns.heatmap(df[numeric_columns].corr(), annot=True, cmap="coolwarm", ax=ax)
63
- st.pyplot(fig)
64
-
65
- with right_col:
66
- st.subheader("馃挰 Chat with Your Data")
67
-
68
- user_query = st.text_input("Ask a question about the data...")
69
-
70
- if user_query and uploaded_file is not None:
71
- # Prepare prompt for AI (limited to 5 columns and rounded)
72
- safe_summary = df.describe().round(2).iloc[:, :5]
73
-
74
- prompt = f"""
75
- You are a data analyst. The user has uploaded a dataset.
76
- Answer the query based on the dataset provided.
77
-
78
- Dataset Overview (first 5 numeric columns):
79
- {safe_summary.to_string()}
80
-
81
- User Question:
82
- {user_query}
83
- """
84
-
85
- try:
86
- model = genai.GenerativeModel("gemini-pro")
87
- response = model.generate_content(prompt)
88
-
89
- if hasattr(response, "text"):
90
- st.write("馃 AI Response:")
91
- st.write(response.text)
92
- else:
93
- st.error("No se recibi贸 una respuesta v谩lida del modelo.")
94
- except Exception as e:
95
- st.error(f"Error al consultar el modelo Gemini: {e}")
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import google.generativeai as genai
4
+ import matplotlib.pyplot as plt
5
+ import seaborn as sns
6
+ import plotly.express as px
7
+
8
+ # Set up page layout
9
+ st.set_page_config(page_title="AI CSV Data Analyst", layout="wide")
10
+
11
+ # Initialize Gemini API (Replace with your API Key)
12
+ GEMINI_API_KEY = "AIzaSyDt0TM6beHrE-f5bvfYXQa6iDACSCfU7go"
13
+ genai.configure(api_key=GEMINI_API_KEY)
14
+
15
+ # Create two columns (70:30 split)
16
+ left_col, right_col = st.columns([7, 3])
17
+
18
+ with left_col:
19
+ st.title("馃搳 AI-Powered CSV Data Analyst")
20
+
21
+ # File Upload
22
+ uploaded_file = st.file_uploader("Upload a CSV or Excel file", type=["csv", "xlsx"])
23
+
24
+ if uploaded_file is not None:
25
+ # Read File
26
+ file_ext = uploaded_file.name.split(".")[-1]
27
+ if file_ext == "csv":
28
+ df = pd.read_csv(uploaded_file)
29
+ elif file_ext == "xlsx":
30
+ df = pd.read_excel(uploaded_file, engine="openpyxl")
31
+
32
+ # Display the DataFrame
33
+ st.subheader("馃搨 Uploaded Data")
34
+ st.dataframe(df)
35
+
36
+ # Data Insights
37
+ st.subheader("馃搱 Data Insights")
38
+
39
+ # Dataset Summary
40
+ st.write(f"**Rows:** {df.shape[0]}, **Columns:** {df.shape[1]}")
41
+ st.write(f"**Missing Values:**\n{df.isnull().sum()}")
42
+
43
+ # Basic Statistics
44
+ st.subheader("馃搳 Statistical Summary")
45
+ st.write(df.describe())
46
+
47
+ # Visualizations
48
+ st.subheader("馃搲 Data Visualizations")
49
+
50
+ # Select Column for Histogram
51
+ numeric_columns = df.select_dtypes(include=["number"]).columns
52
+ if len(numeric_columns) > 0:
53
+ col = st.selectbox("Select a column for histogram:", numeric_columns)
54
+ fig = px.histogram(df, x=col, title=f"Histogram of {col}")
55
+ st.plotly_chart(fig)
56
+
57
+ # Correlation Heatmap
58
+ if len(numeric_columns) > 1:
59
+ st.subheader("馃攳 Correlation Heatmap")
60
+ fig, ax = plt.subplots(figsize=(6, 4))
61
+ sns.heatmap(df[numeric_columns].corr(), annot=True, cmap="coolwarm", ax=ax)
62
+ st.pyplot(fig)
63
+
64
+ with right_col:
65
+ st.subheader("馃挰 Chat with Your Data")
66
+
67
+ user_query = st.text_input("Ask a question about the data...")
68
+
69
+ if user_query and uploaded_file is not None:
70
+ # Prepare prompt for AI
71
+ prompt = f"""
72
+ You are a data analyst. The user has uploaded a dataset.
73
+ Answer the query based on the dataset provided.
74
+
75
+ Dataset Overview:
76
+ {df.describe().to_string()}
77
+
78
+ User Question:
79
+ {user_query}
80
+ """
81
+
82
+ # Get AI response
83
+ model = genai.GenerativeModel("gemini-pro")
84
+ response = model.generate_content(prompt)
85
+
86
+ # Display AI Response
87
+ if response.text:
88
+ st.write("馃 AI Response:")
89
+ st.write(response.text)
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,7 +1,6 @@
1
- streamlit
2
- pandas
3
- matplotlib
4
  seaborn
 
5
  plotly
6
- google-generativeai
7
- openpyxl
 
1
+ google-generativeai
 
 
2
  seaborn
3
+ matplotlib
4
  plotly
5
+ openpyxl
6
+ pandas