Spaces:
Paused
Paused
WaysAhead Global commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -164,11 +164,11 @@ You are an advanced AI specializing in retail analytics. You help users:
|
|
| 164 |
1. Find similar stores based on category and sales performance.
|
| 165 |
2. Generate insights from sales data.
|
| 166 |
3. Create visualizations like bar charts, line charts, and trends.
|
| 167 |
-
4. If a visualization request is made,
|
| 168 |
"""
|
| 169 |
|
| 170 |
agent = create_pandas_dataframe_agent(
|
| 171 |
-
ChatOpenAI(model="gpt-
|
| 172 |
df_kpi,
|
| 173 |
verbose=True,
|
| 174 |
agent_type="openai-tools",
|
|
@@ -187,17 +187,18 @@ if user_query:
|
|
| 187 |
if "import matplotlib.pyplot" in response:
|
| 188 |
st.write("π AI is generating a chart based on your request...")
|
| 189 |
|
| 190 |
-
# β
|
|
|
|
|
|
|
|
|
|
| 191 |
try:
|
| 192 |
-
|
| 193 |
-
exec(response, {}, exec_globals) # Execute AI-generated code
|
| 194 |
|
| 195 |
# β
Capture Matplotlib Figure
|
| 196 |
fig = plt.gcf()
|
| 197 |
buf = BytesIO()
|
| 198 |
fig.savefig(buf, format="png")
|
| 199 |
buf.seek(0)
|
| 200 |
-
image_base64 = base64.b64encode(buf.read()).decode()
|
| 201 |
|
| 202 |
# β
Display Image in Streamlit
|
| 203 |
st.image(buf, caption="π AI-Generated Chart", use_column_width=True)
|
|
@@ -212,6 +213,4 @@ if user_query:
|
|
| 212 |
st.error(f"β οΈ Error: {e}")
|
| 213 |
|
| 214 |
st.markdown("---")
|
| 215 |
-
st.markdown("π **Powered by WaysAhead Global AI Engine**")
|
| 216 |
-
|
| 217 |
-
|
|
|
|
| 164 |
1. Find similar stores based on category and sales performance.
|
| 165 |
2. Generate insights from sales data.
|
| 166 |
3. Create visualizations like bar charts, line charts, and trends.
|
| 167 |
+
4. If a visualization request is made like a heatmap or chart, give proper and full Python code to create the chart.
|
| 168 |
"""
|
| 169 |
|
| 170 |
agent = create_pandas_dataframe_agent(
|
| 171 |
+
ChatOpenAI(model="gpt-4", api_key=openai_api_key),
|
| 172 |
df_kpi,
|
| 173 |
verbose=True,
|
| 174 |
agent_type="openai-tools",
|
|
|
|
| 187 |
if "import matplotlib.pyplot" in response:
|
| 188 |
st.write("π AI is generating a chart based on your request...")
|
| 189 |
|
| 190 |
+
# β
Create a dictionary to store execution variables
|
| 191 |
+
exec_globals = {"df": df_kpi}
|
| 192 |
+
|
| 193 |
+
# β
Execute the AI-generated code
|
| 194 |
try:
|
| 195 |
+
exec(response, {}, exec_globals)
|
|
|
|
| 196 |
|
| 197 |
# β
Capture Matplotlib Figure
|
| 198 |
fig = plt.gcf()
|
| 199 |
buf = BytesIO()
|
| 200 |
fig.savefig(buf, format="png")
|
| 201 |
buf.seek(0)
|
|
|
|
| 202 |
|
| 203 |
# β
Display Image in Streamlit
|
| 204 |
st.image(buf, caption="π AI-Generated Chart", use_column_width=True)
|
|
|
|
| 213 |
st.error(f"β οΈ Error: {e}")
|
| 214 |
|
| 215 |
st.markdown("---")
|
| 216 |
+
st.markdown("π **Powered by WaysAhead Global AI Engine**")
|
|
|
|
|
|