Update app.py
Browse files
app.py
CHANGED
@@ -7,42 +7,46 @@ from langchain_community.vectorstores import FAISS
|
|
7 |
from langchain_openai import ChatOpenAI
|
8 |
from langchain.chains import RetrievalQA
|
9 |
from langchain.schema import Document
|
10 |
-
from datasets import load_dataset
|
11 |
import os
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Title
|
14 |
-
st.title("
|
15 |
|
16 |
# Fetch API keys from environment variables
|
17 |
api_key = os.getenv("OPENAI_API_KEY")
|
18 |
pandasai_api_key = os.getenv("PANDASAI_API_KEY")
|
19 |
|
20 |
-
# Dataset selection
|
21 |
-
st.sidebar.header("Dataset Input Options")
|
22 |
-
input_option = st.sidebar.radio("Select Dataset Input:", ["Use Hugging Face Dataset", "Upload CSV File"])
|
23 |
-
|
24 |
# Initialize session state for the dataframe
|
25 |
if "df" not in st.session_state:
|
26 |
st.session_state.df = None
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
dataset_name = st.sidebar.text_input("Enter Hugging Face Dataset Name:", value="HUPD/hupd")
|
31 |
-
if st.sidebar.button("Load Dataset"):
|
32 |
-
try:
|
33 |
-
dataset = load_dataset(dataset_name, name="sample", split="train", trust_remote_code=True)
|
34 |
-
st.session_state.df = pd.DataFrame(dataset)
|
35 |
-
st.sidebar.success(f"Dataset '{dataset_name}' loaded successfully!")
|
36 |
-
except Exception as e:
|
37 |
-
st.sidebar.error(f"Error loading dataset: {e}")
|
38 |
-
elif input_option == "Upload CSV File":
|
39 |
-
uploaded_file = st.sidebar.file_uploader("Upload CSV File:", type=["csv"])
|
40 |
-
if uploaded_file:
|
41 |
-
try:
|
42 |
-
st.session_state.df = pd.read_csv(uploaded_file)
|
43 |
-
st.sidebar.success("File uploaded successfully!")
|
44 |
-
except Exception as e:
|
45 |
-
st.sidebar.error(f"Error loading file: {e}")
|
46 |
|
47 |
# Show the loaded dataframe preview
|
48 |
if st.session_state.df is not None:
|
@@ -121,4 +125,4 @@ else:
|
|
121 |
if not api_key:
|
122 |
st.error("Missing OpenAI API Key in environment variables.")
|
123 |
if not pandasai_api_key:
|
124 |
-
st.error("Missing PandasAI API Key in environment variables.")
|
|
|
7 |
from langchain_openai import ChatOpenAI
|
8 |
from langchain.chains import RetrievalQA
|
9 |
from langchain.schema import Document
|
10 |
+
from datasets import load_dataset
|
11 |
import os
|
12 |
|
13 |
+
|
14 |
+
# Function to load dataset into session
|
15 |
+
def load_dataset_into_session():
|
16 |
+
input_option = st.sidebar.radio("Select Dataset Input:", ["Use Hugging Face Dataset", "Upload CSV File"])
|
17 |
+
if input_option == "Use Hugging Face Dataset":
|
18 |
+
dataset_name = st.sidebar.text_input("Enter Hugging Face Dataset Name:", value="HUPD/hupd")
|
19 |
+
if st.sidebar.button("Load Dataset"):
|
20 |
+
try:
|
21 |
+
# Ensure `uniform_split=True` is provided for compatibility
|
22 |
+
dataset = load_dataset(dataset_name, name="sample", split="train", trust_remote_code=True, uniform_split=True)
|
23 |
+
st.session_state.df = pd.DataFrame(dataset)
|
24 |
+
st.sidebar.success(f"Dataset '{dataset_name}' loaded successfully!")
|
25 |
+
except Exception as e:
|
26 |
+
st.sidebar.error(f"Error loading dataset: {e}")
|
27 |
+
elif input_option == "Upload CSV File":
|
28 |
+
uploaded_file = st.sidebar.file_uploader("Upload CSV File:", type=["csv"])
|
29 |
+
if uploaded_file:
|
30 |
+
try:
|
31 |
+
st.session_state.df = pd.read_csv(uploaded_file)
|
32 |
+
st.sidebar.success("File uploaded successfully!")
|
33 |
+
except Exception as e:
|
34 |
+
st.sidebar.error(f"Error loading file: {e}")
|
35 |
+
|
36 |
+
|
37 |
# Title
|
38 |
+
st.title("XYZ")
|
39 |
|
40 |
# Fetch API keys from environment variables
|
41 |
api_key = os.getenv("OPENAI_API_KEY")
|
42 |
pandasai_api_key = os.getenv("PANDASAI_API_KEY")
|
43 |
|
|
|
|
|
|
|
|
|
44 |
# Initialize session state for the dataframe
|
45 |
if "df" not in st.session_state:
|
46 |
st.session_state.df = None
|
47 |
|
48 |
+
# Call the function to load the dataset
|
49 |
+
load_dataset_into_session()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
# Show the loaded dataframe preview
|
52 |
if st.session_state.df is not None:
|
|
|
125 |
if not api_key:
|
126 |
st.error("Missing OpenAI API Key in environment variables.")
|
127 |
if not pandasai_api_key:
|
128 |
+
st.error("Missing PandasAI API Key in environment variables.")
|