Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +122 -0
- favicon.ico +0 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
import plotly.express as px
|
6 |
+
from e2b_code_interpreter import Sandbox
|
7 |
+
from groq import Groq
|
8 |
+
import re
|
9 |
+
from streamlit_lottie import st_lottie
|
10 |
+
import requests
|
11 |
+
|
12 |
+
# Load environment variables
|
13 |
+
load_dotenv()
|
14 |
+
|
15 |
+
# Retrieve API keys from the environment
|
16 |
+
E2B_API_KEY = os.getenv("E2B_API_KEY")
|
17 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
18 |
+
|
19 |
+
# Groq client and model setup
|
20 |
+
client = Groq(api_key=GROQ_API_KEY)
|
21 |
+
MODEL_NAME = 'llama-3.1-70b-versatile'
|
22 |
+
|
23 |
+
def load_lottie_url(url: str):
|
24 |
+
r = requests.get(url)
|
25 |
+
if r.status_code != 200:
|
26 |
+
return None
|
27 |
+
return r.json()
|
28 |
+
|
29 |
+
def upload_and_display_csv():
|
30 |
+
uploaded_file = st.file_uploader("Upload your CSV file", type="csv")
|
31 |
+
if uploaded_file:
|
32 |
+
try:
|
33 |
+
dataframe = pd.read_csv(uploaded_file)
|
34 |
+
st.dataframe(dataframe.head(), use_container_width=True)
|
35 |
+
return dataframe
|
36 |
+
except Exception as e:
|
37 |
+
st.error(f"Error loading CSV: {str(e)}")
|
38 |
+
return None
|
39 |
+
return None
|
40 |
+
|
41 |
+
def plot_interactive_graph(dataframe, x_column, y_column):
|
42 |
+
fig = px.scatter(dataframe, x=x_column, y=y_column, title=f"{x_column} vs {y_column}", template="plotly_dark")
|
43 |
+
fig.update_layout(font=dict(color="white"), title=dict(font=dict(size=20, color="white")))
|
44 |
+
st.plotly_chart(fig, use_container_width=True)
|
45 |
+
|
46 |
+
st.set_page_config(page_title="Theaimart", layout="wide", page_icon="favicon.ico")
|
47 |
+
|
48 |
+
# Custom CSS to fix selectbox issues
|
49 |
+
st.markdown("""
|
50 |
+
<style>
|
51 |
+
/* Apply dark theme to entire app */
|
52 |
+
.stApp {
|
53 |
+
background-color: #0e1117;
|
54 |
+
color: white;
|
55 |
+
}
|
56 |
+
|
57 |
+
/* General fix for inputs and text */
|
58 |
+
.stTextInput, .stSelectbox, .stFileUploader {
|
59 |
+
background-color: #1f2937 !important;
|
60 |
+
color: white !important;
|
61 |
+
border-radius: 5px;
|
62 |
+
border: 1px solid #2563eb !important;
|
63 |
+
}
|
64 |
+
|
65 |
+
/* Ensure all inner elements inherit colors */
|
66 |
+
.stSelectbox div[data-baseweb="select"] * {
|
67 |
+
color: white !important;
|
68 |
+
background-color: #1f2937 !important;
|
69 |
+
}
|
70 |
+
|
71 |
+
/* Fix dropdown text visibility */
|
72 |
+
.stSelectbox div[data-baseweb="select"] div {
|
73 |
+
color: white !important;
|
74 |
+
}
|
75 |
+
|
76 |
+
/* Dropdown hover and focus */
|
77 |
+
.stSelectbox div[data-baseweb="select"]:hover {
|
78 |
+
background-color: #2d3748 !important;
|
79 |
+
}
|
80 |
+
.stSelectbox div[data-baseweb="select"]:focus {
|
81 |
+
background-color: #2d3748 !important;
|
82 |
+
color: white !important;
|
83 |
+
}
|
84 |
+
|
85 |
+
/* Ensure SVG (arrow icon) visibility */
|
86 |
+
.stSelectbox svg {
|
87 |
+
fill: white !important;
|
88 |
+
}
|
89 |
+
</style>
|
90 |
+
""", unsafe_allow_html=True)
|
91 |
+
|
92 |
+
# Main UI with two columns
|
93 |
+
st.title("GSV: AI-Powered Data Analysis App")
|
94 |
+
|
95 |
+
# Load Lottie animation
|
96 |
+
lottie_url = "https://assets5.lottiefiles.com/packages/lf20_qp1q7mct.json"
|
97 |
+
lottie_json = load_lottie_url(lottie_url)
|
98 |
+
st_lottie(lottie_json, height=200)
|
99 |
+
|
100 |
+
col1, col2 = st.columns([2, 1])
|
101 |
+
|
102 |
+
with col1:
|
103 |
+
st.header("📈 Data Visualization")
|
104 |
+
dataframe = upload_and_display_csv()
|
105 |
+
if dataframe is not None:
|
106 |
+
col_x, col_y = st.columns(2)
|
107 |
+
with col_x:
|
108 |
+
x_column = st.selectbox("Select X-axis", dataframe.columns)
|
109 |
+
with col_y:
|
110 |
+
y_column = st.selectbox("Select Y-axis", dataframe.columns)
|
111 |
+
|
112 |
+
if st.button("Generate Interactive Plot"):
|
113 |
+
plot_interactive_graph(dataframe, x_column, y_column)
|
114 |
+
|
115 |
+
with col2:
|
116 |
+
st.header("🤖 Chat with CSV")
|
117 |
+
user_query = st.text_area("Ask a question about your data")
|
118 |
+
if st.button("Ask AI Assistant"):
|
119 |
+
st.write("AI is processing...")
|
120 |
+
|
121 |
+
st.markdown("---")
|
122 |
+
st.markdown("Created with ❤️ by theaimart")
|
favicon.ico
ADDED
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python-dotenv
|
2 |
+
streamlit
|
3 |
+
pandas
|
4 |
+
plotly
|
5 |
+
e2b-code-interpreter
|
6 |
+
groq
|
7 |
+
streamlit-lottie
|
8 |
+
requests
|