-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataAnalysisAssistant.py
More file actions
54 lines (49 loc) · 1.68 KB
/
Copy pathdataAnalysisAssistant.py
File metadata and controls
54 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import streamlit as st
import pandas as pd
from google import genai
from google.genai import types
if "GEMINI_KEY" not in st.secrets:
st.error("Missing API key. Add GEMINI_KEY to .streamlit/secrets.toml")
st.stop()
client = genai.Client(api_key=st.secrets["GEMINI_KEY"])
st.title("🤔 Data Analysis Assistant")
try:
uploaded = st.file_uploader("Upload CSV", type="csv")
if uploaded:
df = pd.read_csv(uploaded)
st.dataframe(df.head())
data_summary = f"""Dataset: {uploaded.name}
Rows: {len(df)}, Columns: {len(df.columns)}
Column names: {', '.join(df.columns)}
Data types:
{df.dtypes.to_string()}
Summary statistics:
{df.describe().to_string()}
First 5 rows:
{df.head().to_string()}
Missing values:
{df.isnull().sum().to_string()}"""
# Chat interface
question = st.text_input("Ask about the data")
step_by_step = st.checkbox(
"Show reasoning (chain-of-thought)")
if question:
if step_by_step:
prompt = (f"""{data_summary}
{question}\n\n
Think step by step:\n
1) What data is relevant?\n
2) What patterns do you see?\n
3) What are the limitations?\n
4) Give your conclusion.""")
else:
prompt = question
with st.spinner("Analyzing..."):
r = client.models.generate_content(
model="gemini-2.5-flash-lite",
contents=prompt,
)
st.markdown(r.text)
except Exception as e:
print (f"Oops! Something went wrong: {str(e)}. Try again!")
st.error(f"Oops! Something went wrong: {str(e)}. Try again!")