Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,54 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from pandasai.llm.openai import OpenAI
|
| 3 |
-
import pandas as pd
|
| 4 |
-
from pandasai import SmartDataframe, Agent
|
| 5 |
-
import io
|
| 6 |
import os
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pandasai.llm import GoogleGemini
|
| 2 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import os
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from pandasai import SmartDataframe
|
| 6 |
+
from pandasai.responses.response_parser import ResponseParser
|
| 7 |
+
|
| 8 |
+
class StreamLitResponse(ResponseParser):
|
| 9 |
+
def __init__(self,context) -> None:
|
| 10 |
+
super().__init__(context)
|
| 11 |
+
def format_dataframe(self,result):
|
| 12 |
+
st.dataframe(result['value'])
|
| 13 |
+
return
|
| 14 |
+
def format_plot(self,result):
|
| 15 |
+
st.image(result['value'])
|
| 16 |
+
return
|
| 17 |
+
def format_other(self, result):
|
| 18 |
+
st.write(result['value'])
|
| 19 |
+
return
|
| 20 |
+
|
| 21 |
+
gemini_api_key = os.environ['Gemini']
|
| 22 |
+
|
| 23 |
+
def generateResponse(dataFrame,prompt):
|
| 24 |
+
llm = GoogleGemini(api_key=gemini_api_key)
|
| 25 |
+
pandas_agent = SmartDataframe(dataFrame,config={"llm":llm, "response_parser":StreamLitResponse})
|
| 26 |
+
answer = pandas_agent.chat(prompt)
|
| 27 |
+
return answer
|
| 28 |
+
|
| 29 |
+
st.write("# Brave Retail Insights")
|
| 30 |
+
st.write("##### Engage in insightful conversations with your data through powerful visualizations")
|
| 31 |
+
with st.sidebar:
|
| 32 |
+
st.title("Brave Retail Insights")
|
| 33 |
+
|
| 34 |
+
# Added a divider
|
| 35 |
+
st.divider()
|
| 36 |
+
# Add content to the sidebar/drawer
|
| 37 |
+
with st.expander("Data Visualization"):
|
| 38 |
+
st.write("<div>Developed by - <span style=\"color: cyan; font-size: 24px; font-weight: 600;\">Rairo</span></div>",unsafe_allow_html=True)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
uploaded_file = "alaba.csv"
|
| 42 |
+
if uploaded_file is not None:
|
| 43 |
+
# Read the CSV file
|
| 44 |
+
df = pd.read_csv(uploaded_file)
|
| 45 |
+
|
| 46 |
+
# Display the data
|
| 47 |
+
with st.expander("Preview"):
|
| 48 |
+
st.write(df.head())
|
| 49 |
+
|
| 50 |
+
# Plot the data
|
| 51 |
+
user_input = st.text_input("Type your message here",placeholder="Ask me about your data")
|
| 52 |
+
if user_input:
|
| 53 |
+
answer = generateResponse(dataFrame=df,prompt=user_input)
|
| 54 |
+
st.write(answer)
|