Spaces:
Sleeping
Sleeping
Update app2.py
Browse files
app2.py
CHANGED
@@ -16,11 +16,13 @@ def initialize_llm(model_choice):
|
|
16 |
if not groq_api_key:
|
17 |
st.error("Groq API key is missing. Please set the GROQ_API_KEY environment variable.")
|
18 |
return None
|
|
|
19 |
return ChatGroq(groq_api_key=groq_api_key, model="groq/llama-3.3-70b-versatile")
|
20 |
elif model_choice == "GPT-4o":
|
21 |
if not openai_api_key:
|
22 |
st.error("OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable.")
|
23 |
return None
|
|
|
24 |
return OpenAI(api_token=openai_api_key)
|
25 |
|
26 |
def load_dataset_into_session():
|
@@ -31,7 +33,6 @@ def load_dataset_into_session():
|
|
31 |
dataset_name = st.text_input("Enter Hugging Face Dataset Name:", value="HUPD/hupd")
|
32 |
if st.button("Load Dataset"):
|
33 |
try:
|
34 |
-
# Using the original parameters
|
35 |
dataset = load_dataset(
|
36 |
dataset_name,
|
37 |
name="sample",
|
@@ -43,14 +44,17 @@ def load_dataset_into_session():
|
|
43 |
st.success(f"Dataset '{dataset_name}' loaded successfully!")
|
44 |
st.dataframe(st.session_state.df.head(10))
|
45 |
except Exception as e:
|
46 |
-
st.error(f"Error: {e}")
|
47 |
|
48 |
elif input_option == "Upload CSV File":
|
49 |
uploaded_file = st.file_uploader("Upload CSV File:", type=["csv"])
|
50 |
if uploaded_file:
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
if "df" not in st.session_state:
|
56 |
st.session_state.df = None
|
@@ -58,7 +62,7 @@ if "df" not in st.session_state:
|
|
58 |
# Streamlit app
|
59 |
st.title("Chat With Your Dataset Using PandasAI")
|
60 |
|
61 |
-
# LLM Selection
|
62 |
st.sidebar.title("Choose Your LLM")
|
63 |
model_choice = st.sidebar.radio(
|
64 |
"Select a model:",
|
@@ -71,11 +75,11 @@ llm = initialize_llm(model_choice)
|
|
71 |
if not llm:
|
72 |
st.stop()
|
73 |
|
74 |
-
# Dataset Loading
|
75 |
-
|
76 |
load_dataset_into_session()
|
77 |
|
78 |
-
#
|
79 |
if st.session_state.df is not None:
|
80 |
st.subheader("Ask Questions About Your Dataset")
|
81 |
chat_df = SmartDataframe(st.session_state.df, config={"llm": llm})
|
@@ -87,8 +91,8 @@ if st.session_state.df is not None:
|
|
87 |
st.write("### Response:")
|
88 |
st.write(response)
|
89 |
|
90 |
-
# Check for keywords
|
91 |
-
if any(keyword in user_query.lower() for keyword in ["plot", "graph", "draw", "visualize", "chart", "
|
92 |
st.write("### Generating Plot...")
|
93 |
try:
|
94 |
chat_df.chat(user_query)
|
|
|
16 |
if not groq_api_key:
|
17 |
st.error("Groq API key is missing. Please set the GROQ_API_KEY environment variable.")
|
18 |
return None
|
19 |
+
st.success("Using model: llama-3.3-70b (Groq)")
|
20 |
return ChatGroq(groq_api_key=groq_api_key, model="groq/llama-3.3-70b-versatile")
|
21 |
elif model_choice == "GPT-4o":
|
22 |
if not openai_api_key:
|
23 |
st.error("OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable.")
|
24 |
return None
|
25 |
+
st.success("Using model: GPT-4o (OpenAI)")
|
26 |
return OpenAI(api_token=openai_api_key)
|
27 |
|
28 |
def load_dataset_into_session():
|
|
|
33 |
dataset_name = st.text_input("Enter Hugging Face Dataset Name:", value="HUPD/hupd")
|
34 |
if st.button("Load Dataset"):
|
35 |
try:
|
|
|
36 |
dataset = load_dataset(
|
37 |
dataset_name,
|
38 |
name="sample",
|
|
|
44 |
st.success(f"Dataset '{dataset_name}' loaded successfully!")
|
45 |
st.dataframe(st.session_state.df.head(10))
|
46 |
except Exception as e:
|
47 |
+
st.error(f"Error loading dataset: {e}")
|
48 |
|
49 |
elif input_option == "Upload CSV File":
|
50 |
uploaded_file = st.file_uploader("Upload CSV File:", type=["csv"])
|
51 |
if uploaded_file:
|
52 |
+
try:
|
53 |
+
st.session_state.df = pd.read_csv(uploaded_file)
|
54 |
+
st.success("File uploaded successfully!")
|
55 |
+
st.dataframe(st.session_state.df.head(10))
|
56 |
+
except Exception as e:
|
57 |
+
st.error(f"Error reading file: {e}")
|
58 |
|
59 |
if "df" not in st.session_state:
|
60 |
st.session_state.df = None
|
|
|
62 |
# Streamlit app
|
63 |
st.title("Chat With Your Dataset Using PandasAI")
|
64 |
|
65 |
+
# Section 1: LLM Selection
|
66 |
st.sidebar.title("Choose Your LLM")
|
67 |
model_choice = st.sidebar.radio(
|
68 |
"Select a model:",
|
|
|
75 |
if not llm:
|
76 |
st.stop()
|
77 |
|
78 |
+
# Section 2: Dataset Loading
|
79 |
+
st.header("Dataset Selection")
|
80 |
load_dataset_into_session()
|
81 |
|
82 |
+
# Section 3: Query and Interaction
|
83 |
if st.session_state.df is not None:
|
84 |
st.subheader("Ask Questions About Your Dataset")
|
85 |
chat_df = SmartDataframe(st.session_state.df, config={"llm": llm})
|
|
|
91 |
st.write("### Response:")
|
92 |
st.write(response)
|
93 |
|
94 |
+
# Check for plot-related keywords
|
95 |
+
if any(keyword in user_query.lower() for keyword in ["plot", "graph", "draw", "visualize", "chart", "visualise"]):
|
96 |
st.write("### Generating Plot...")
|
97 |
try:
|
98 |
chat_df.chat(user_query)
|