Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -123,27 +123,9 @@ if "df" in st.session_state:
|
|
123 |
if st.button("Run Query"):
|
124 |
with st.spinner("Running query..."):
|
125 |
try:
|
126 |
-
|
127 |
-
max_rows = 1000
|
128 |
-
total_rows = len(df)
|
129 |
-
results = []
|
130 |
-
|
131 |
-
for start in range(0, total_rows, max_rows):
|
132 |
-
chunk = df.iloc[start:start + max_rows]
|
133 |
-
chunk.to_csv("chunk_data.csv", index=False)
|
134 |
-
partial_agent = create_csv_agent(
|
135 |
-
ChatOpenAI(temperature=0, model="gpt-4", api_key=os.getenv("OPENAI_API_KEY")),
|
136 |
-
path=["chunk_data.csv"],
|
137 |
-
verbose=True,
|
138 |
-
agent_type=AgentType.OPENAI_FUNCTIONS,
|
139 |
-
allow_dangerous_code=True
|
140 |
-
)
|
141 |
-
result = partial_agent.invoke(query)
|
142 |
-
results.append(result)
|
143 |
-
|
144 |
st.success("Query executed successfully!")
|
145 |
st.write("### Query Result:")
|
146 |
-
st.write(
|
147 |
-
|
148 |
except Exception as e:
|
149 |
-
st.error(f"Error executing query: {e}")
|
|
|
123 |
if st.button("Run Query"):
|
124 |
with st.spinner("Running query..."):
|
125 |
try:
|
126 |
+
result = csv_agent.invoke(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
st.success("Query executed successfully!")
|
128 |
st.write("### Query Result:")
|
129 |
+
st.write(result)
|
|
|
130 |
except Exception as e:
|
131 |
+
st.error(f"Error executing query: {e}")
|