File size: 1,902 Bytes
0404f33
96ede08
 
0404f33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55c6832
0404f33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
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
46
47
48
49
50
51
52
53
54
from pandasai.llm import GoogleGemini
import streamlit as st
import os
import pandas as pd
from pandasai import SmartDataframe
from pandasai.responses.response_parser import  ResponseParser

class StreamLitResponse(ResponseParser):
        def __init__(self,context) -> None:
              super().__init__(context)
        def format_dataframe(self,result):
               st.dataframe(result['value'])
               return
        def format_plot(self,result):
               st.image(result['value'])
               return
        def format_other(self, result):
               st.write(result['value'])
               return

gemini_api_key = os.environ['Gemini']

def generateResponse(dataFrame,prompt):
        llm = GoogleGemini(api_key=gemini_api_key)
        pandas_agent = SmartDataframe(dataFrame,config={"llm":llm, "response_parser":StreamLitResponse})
        answer = pandas_agent.chat(prompt)
        return answer

st.write("# Brave Retail Insights")
st.write("##### Engage in insightful conversations with your data through powerful visualizations")
with st.sidebar:
        st.title("Brave Retail Insights")
        
        # Added a divider
        st.divider()
        # Add content to the sidebar/drawer
        with st.expander("Data Visualization"):
            st.write("<div>Developed by - <span style=\"color: cyan; font-size: 24px; font-weight: 600;\">Rairo</span></div>",unsafe_allow_html=True)


uploaded_file = "alaba.csv"
if uploaded_file is not None:
        # Read the CSV file
        df = pd.read_csv(uploaded_file)

        # Display the data
        with st.expander("Preview"):
            st.write(df.head())

        # Plot the data
        user_input = st.text_input("Type your message here",placeholder="Ask me about your data")
        if user_input:
                answer = generateResponse(dataFrame=df,prompt=user_input)
                st.write(answer)