Spaces:
Paused
Paused
WaysAhead Global commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import seaborn as sns
|
|
| 7 |
from sklearn.cluster import KMeans
|
| 8 |
from statsmodels.tsa.holtwinters import ExponentialSmoothing
|
| 9 |
from langchain_openai import ChatOpenAI
|
|
|
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
|
| 12 |
# β
Load Environment Variables
|
|
@@ -43,6 +44,10 @@ st.set_page_config(page_title="AI Store Replacement, Demand Prediction & Chatbot
|
|
| 43 |
# β
Title
|
| 44 |
st.title("π AI-Powered Store Replacement, Demand Prediction & Chatbot")
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# β
Store Replacement System
|
| 47 |
st.subheader("π¬ AI-Based Store Replacement")
|
| 48 |
|
|
@@ -86,17 +91,11 @@ if selected_mall:
|
|
| 86 |
existing_stores = set(mall_data["Store_Brand"].unique())
|
| 87 |
potential_replacements = list(all_stores - existing_stores)
|
| 88 |
|
| 89 |
-
# β
Debugging: Check available replacements
|
| 90 |
-
st.write(f"π **Available Replacement Stores:** {potential_replacements}")
|
| 91 |
-
|
| 92 |
if potential_replacements:
|
| 93 |
replacement_prompt = f"Based on the category {store_category}, suggest 3 stores from the list below that are not already in {selected_mall}. The stores should match the mallβs customer base. Store List: {potential_replacements}"
|
| 94 |
replacement_response = llm.invoke(replacement_prompt).content
|
| 95 |
replacement_stores = replacement_response.split(", ")
|
| 96 |
|
| 97 |
-
# β
Debugging: Print AI Response
|
| 98 |
-
st.write(f"π§ **AI Raw Response:** {replacement_response}")
|
| 99 |
-
|
| 100 |
st.success(f"π **Recommended Replacement Stores:**")
|
| 101 |
for replacement_store in replacement_stores:
|
| 102 |
store_data = df[df["Store_Brand"] == replacement_store]
|
|
@@ -114,31 +113,33 @@ if selected_mall:
|
|
| 114 |
expected_margin = store_data["Gross_Margin"].mean()
|
| 115 |
|
| 116 |
st.write(f"**{replacement_store}**")
|
| 117 |
-
st.write(f"π **
|
| 118 |
-
st.write(f"π£ **
|
| 119 |
-
st.write(f"π° **
|
| 120 |
-
st.write(f"π **
|
| 121 |
|
| 122 |
# β
Justification
|
| 123 |
-
justification_prompt = f"Explain why {replacement_store} is a good replacement for {store_to_replace} in {selected_mall}.
|
| 124 |
justification = llm.invoke(justification_prompt).content
|
| 125 |
st.write(f"π€ **AI Justification:** {justification}")
|
| 126 |
|
| 127 |
# β
AI Chatbot for Dynamic Insights
|
| 128 |
st.subheader("π¬ AI-Powered Chatbot")
|
| 129 |
|
| 130 |
-
# AI Chatbot using
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
| 132 |
if user_query:
|
| 133 |
with st.spinner("π€ AI is thinking..."):
|
| 134 |
try:
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
st.markdown(f"π€ **AI Response:** {chat_response}")
|
| 138 |
|
| 139 |
except Exception as e:
|
| 140 |
st.error(f"β AI Error: {str(e)}")
|
| 141 |
|
| 142 |
# β
Footer
|
| 143 |
st.markdown("---")
|
| 144 |
-
st.markdown("π‘ Built with β€οΈ using **
|
|
|
|
| 7 |
from sklearn.cluster import KMeans
|
| 8 |
from statsmodels.tsa.holtwinters import ExponentialSmoothing
|
| 9 |
from langchain_openai import ChatOpenAI
|
| 10 |
+
from pandasai import SmartDatalake
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
|
| 13 |
# β
Load Environment Variables
|
|
|
|
| 44 |
# β
Title
|
| 45 |
st.title("π AI-Powered Store Replacement, Demand Prediction & Chatbot")
|
| 46 |
|
| 47 |
+
# β
Data Preview Section
|
| 48 |
+
st.subheader("π Full Data Preview - KPI Sheet")
|
| 49 |
+
st.dataframe(df)
|
| 50 |
+
|
| 51 |
# β
Store Replacement System
|
| 52 |
st.subheader("π¬ AI-Based Store Replacement")
|
| 53 |
|
|
|
|
| 91 |
existing_stores = set(mall_data["Store_Brand"].unique())
|
| 92 |
potential_replacements = list(all_stores - existing_stores)
|
| 93 |
|
|
|
|
|
|
|
|
|
|
| 94 |
if potential_replacements:
|
| 95 |
replacement_prompt = f"Based on the category {store_category}, suggest 3 stores from the list below that are not already in {selected_mall}. The stores should match the mallβs customer base. Store List: {potential_replacements}"
|
| 96 |
replacement_response = llm.invoke(replacement_prompt).content
|
| 97 |
replacement_stores = replacement_response.split(", ")
|
| 98 |
|
|
|
|
|
|
|
|
|
|
| 99 |
st.success(f"π **Recommended Replacement Stores:**")
|
| 100 |
for replacement_store in replacement_stores:
|
| 101 |
store_data = df[df["Store_Brand"] == replacement_store]
|
|
|
|
| 113 |
expected_margin = store_data["Gross_Margin"].mean()
|
| 114 |
|
| 115 |
st.write(f"**{replacement_store}**")
|
| 116 |
+
st.write(f"π **Projected Sales:** AED {forecast_sales:,.2f}")
|
| 117 |
+
st.write(f"π£ **Projected Footfall:** {expected_footfall:,.0f} visitors")
|
| 118 |
+
st.write(f"π° **Projected Margin:** AED {expected_margin:,.2f}")
|
| 119 |
+
st.write(f"π **Projected Conversion Rate:** {expected_conversion:.2f}%")
|
| 120 |
|
| 121 |
# β
Justification
|
| 122 |
+
justification_prompt = f"Explain why {replacement_store} is a good replacement for {store_to_replace} in {selected_mall}. Include numeric KPIs: expected sales, footfall, conversion rate, and profit margins."
|
| 123 |
justification = llm.invoke(justification_prompt).content
|
| 124 |
st.write(f"π€ **AI Justification:** {justification}")
|
| 125 |
|
| 126 |
# β
AI Chatbot for Dynamic Insights
|
| 127 |
st.subheader("π¬ AI-Powered Chatbot")
|
| 128 |
|
| 129 |
+
# AI Chatbot using PandasAI
|
| 130 |
+
llm_pandas = ChatOpenAI(model="gpt-3.5-turbo", api_key=openai_api_key)
|
| 131 |
+
sdl = SmartDatalake([df], config={"llm": llm_pandas, "enable_cache": False})
|
| 132 |
+
|
| 133 |
+
user_query = st.text_input("π Ask AI About Your Data:")
|
| 134 |
if user_query:
|
| 135 |
with st.spinner("π€ AI is thinking..."):
|
| 136 |
try:
|
| 137 |
+
response = sdl.chat(user_query)
|
| 138 |
+
st.markdown(f"π€ **AI:** {response}")
|
|
|
|
| 139 |
|
| 140 |
except Exception as e:
|
| 141 |
st.error(f"β AI Error: {str(e)}")
|
| 142 |
|
| 143 |
# β
Footer
|
| 144 |
st.markdown("---")
|
| 145 |
+
st.markdown("π‘ Built with β€οΈ using **AI-Powered Store Replacement & Demand Prediction**")
|