Spaces:
Paused
Paused
WaysAhead Global commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,8 @@ from langchain.chains import LLMChain
|
|
| 9 |
from langchain.prompts import PromptTemplate
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from pycaret.regression import setup as setup_reg, compare_models as compare_reg, predict_model
|
| 12 |
-
from pandasai import
|
|
|
|
| 13 |
from langchain_community.document_loaders import UnstructuredExcelLoader, CSVLoader
|
| 14 |
from langchain_community.vectorstores import Chroma
|
| 15 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
@@ -86,10 +87,11 @@ try:
|
|
| 86 |
except Exception as e:
|
| 87 |
st.error(f"β Error training AI embeddings with ChromaDB: {e}")
|
| 88 |
|
| 89 |
-
# β
Initialize Pandas AI Agent
|
| 90 |
st.info("π§ Initializing Pandas AI Agent...")
|
| 91 |
try:
|
| 92 |
-
|
|
|
|
| 93 |
st.success("β
Pandas AI Agent Initialized!")
|
| 94 |
except Exception as e:
|
| 95 |
st.error(f"β Error initializing Pandas AI Agent: {e}")
|
|
@@ -137,19 +139,17 @@ if selected_mall:
|
|
| 137 |
for competitor in competitor_list:
|
| 138 |
st.write(f"- {competitor}")
|
| 139 |
|
| 140 |
-
# β
AI Chatbot
|
| 141 |
st.subheader("π¬ AI-Powered Business Chatbot")
|
| 142 |
user_query = st.text_input("π Ask AI About Your Data:")
|
| 143 |
|
| 144 |
if user_query:
|
| 145 |
st.info(f"π§ Processing AI Query: {user_query}")
|
| 146 |
-
search_results = vectorstore.similarity_search(user_query)
|
| 147 |
-
response = "\n".join([doc.page_content for doc in search_results])
|
| 148 |
-
|
| 149 |
if "chart" in user_query.lower():
|
| 150 |
st.image(chart_path, caption="Generated Chart", use_column_width=True)
|
| 151 |
else:
|
| 152 |
-
|
|
|
|
| 153 |
|
| 154 |
st.markdown("---")
|
| 155 |
-
st.markdown("π‘ Built with β€οΈ using **
|
|
|
|
| 9 |
from langchain.prompts import PromptTemplate
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from pycaret.regression import setup as setup_reg, compare_models as compare_reg, predict_model
|
| 12 |
+
from pandasai import SmartDataframe
|
| 13 |
+
from pandasai.llm.openai import OpenAI
|
| 14 |
from langchain_community.document_loaders import UnstructuredExcelLoader, CSVLoader
|
| 15 |
from langchain_community.vectorstores import Chroma
|
| 16 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
st.error(f"β Error training AI embeddings with ChromaDB: {e}")
|
| 89 |
|
| 90 |
+
# β
Initialize Pandas AI Agent (SmartDataframe)
|
| 91 |
st.info("π§ Initializing Pandas AI Agent...")
|
| 92 |
try:
|
| 93 |
+
llm = OpenAI(api_token=openai_api_key)
|
| 94 |
+
df_smart = SmartDataframe(df_kpi, config={"llm": llm})
|
| 95 |
st.success("β
Pandas AI Agent Initialized!")
|
| 96 |
except Exception as e:
|
| 97 |
st.error(f"β Error initializing Pandas AI Agent: {e}")
|
|
|
|
| 139 |
for competitor in competitor_list:
|
| 140 |
st.write(f"- {competitor}")
|
| 141 |
|
| 142 |
+
# β
AI Chatbot (Using PandasAI + ChromaDB)
|
| 143 |
st.subheader("π¬ AI-Powered Business Chatbot")
|
| 144 |
user_query = st.text_input("π Ask AI About Your Data:")
|
| 145 |
|
| 146 |
if user_query:
|
| 147 |
st.info(f"π§ Processing AI Query: {user_query}")
|
|
|
|
|
|
|
|
|
|
| 148 |
if "chart" in user_query.lower():
|
| 149 |
st.image(chart_path, caption="Generated Chart", use_column_width=True)
|
| 150 |
else:
|
| 151 |
+
ai_response = df_smart.chat(user_query)
|
| 152 |
+
st.markdown(f"π€ **AI Response:** {ai_response}")
|
| 153 |
|
| 154 |
st.markdown("---")
|
| 155 |
+
st.markdown("π‘ Built with β€οΈ using **ChromaDB, AI Store Replacement & Business Analytics**")
|