Update app3.py
Browse files
app3.py
CHANGED
@@ -15,13 +15,19 @@ import logging
|
|
15 |
logging.basicConfig(level=logging.DEBUG)
|
16 |
logger = logging.getLogger(__name__)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Title of the app
|
19 |
st.title("PandasAI Data Analyzer with RAG")
|
20 |
|
21 |
-
# Sidebar for API keys
|
22 |
-
api_key = st.sidebar.text_input("OpenAI API Key", type="password")
|
23 |
-
pandasai_api_key = st.sidebar.text_input("PandasAI API Key", type="password")
|
24 |
-
|
25 |
# Function to load datasets into session
|
26 |
def load_dataset_into_session():
|
27 |
input_option = st.radio(
|
@@ -83,10 +89,6 @@ load_dataset_into_session()
|
|
83 |
if st.session_state.df is not None:
|
84 |
df = st.session_state.df
|
85 |
try:
|
86 |
-
# Set API keys in environment variables
|
87 |
-
os.environ["OPENAI_API_KEY"] = api_key
|
88 |
-
os.environ["PANDASAI_API_KEY"] = pandasai_api_key
|
89 |
-
|
90 |
# Initialize PandasAI Agent
|
91 |
agent = Agent(df)
|
92 |
|
|
|
15 |
logging.basicConfig(level=logging.DEBUG)
|
16 |
logger = logging.getLogger(__name__)
|
17 |
|
18 |
+
# Fetch API keys from environment variables
|
19 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
20 |
+
pandasai_api_key = os.getenv("PANDASAI_API_KEY")
|
21 |
+
|
22 |
+
# Check for missing keys
|
23 |
+
if not api_key or not pandasai_api_key:
|
24 |
+
raise EnvironmentError(
|
25 |
+
"API keys are missing! Ensure both 'OPENAI_API_KEY' and 'PANDASAI_API_KEY' are set in the environment."
|
26 |
+
)
|
27 |
+
|
28 |
# Title of the app
|
29 |
st.title("PandasAI Data Analyzer with RAG")
|
30 |
|
|
|
|
|
|
|
|
|
31 |
# Function to load datasets into session
|
32 |
def load_dataset_into_session():
|
33 |
input_option = st.radio(
|
|
|
89 |
if st.session_state.df is not None:
|
90 |
df = st.session_state.df
|
91 |
try:
|
|
|
|
|
|
|
|
|
92 |
# Initialize PandasAI Agent
|
93 |
agent = Agent(df)
|
94 |
|