WaysAhead Global commited on
Commit
f525de7
Β·
verified Β·
1 Parent(s): 0afade5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
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"πŸ“Š **Predicted Sales:** AED {forecast_sales:,.2f}")
118
- st.write(f"πŸ‘£ **Expected Footfall:** {expected_footfall:,.0f} visitors")
119
- st.write(f"πŸ’° **Expected Margin:** AED {expected_margin:,.2f}")
120
- st.write(f"πŸ”„ **Expected Conversion Rate:** {expected_conversion:.2f}%")
121
 
122
  # βœ… Justification
123
- justification_prompt = f"Explain why {replacement_store} is a good replacement for {store_to_replace} in {selected_mall}. Consider factors like category relevance, expected sales, and competitor presence."
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 LangChain
131
- user_query = st.text_input("πŸ” Ask anything about store performance, competitors, or pricing:")
 
 
 
132
  if user_query:
133
  with st.spinner("πŸ€– AI is thinking..."):
134
  try:
135
- chat_prompt = f"Answer the following retail business question based on your market knowledge: {user_query}"
136
- chat_response = llm.invoke(chat_prompt).content
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 **LangChain AI for Store Replacement & Demand Prediction**")
 
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**")