Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,36 @@ import pandas as pd
|
|
6 |
from datetime import datetime
|
7 |
from st_on_hover_tabs import on_hover_tabs
|
8 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Initialize Firebase app
|
12 |
if not firebase_admin._apps:
|
13 |
cred = credentials.Certificate("ecomplaintbook-firebase-adminsdk-4q5bo-1f83312d02.json")
|
@@ -15,6 +43,14 @@ if not firebase_admin._apps:
|
|
15 |
|
16 |
db = firestore.client()
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Function to fetch user profile from Firebase
|
20 |
def fetch_user_profile_from_firebase(user_id):
|
@@ -82,14 +118,7 @@ def main():
|
|
82 |
st.title("Navigation Bar")
|
83 |
st.header("Complaints")
|
84 |
# Then query to list all users
|
85 |
-
complaints_ref = db.collection('complaints')
|
86 |
-
|
87 |
-
complaints_list = []
|
88 |
-
for doc in complaints_ref.stream():
|
89 |
-
a = doc.to_dict()
|
90 |
-
complaints_list.append(a)
|
91 |
|
92 |
-
complaints_df = pd.DataFrame(complaints_list)
|
93 |
|
94 |
st.dataframe(complaints_df)
|
95 |
|
@@ -98,8 +127,19 @@ def main():
|
|
98 |
st.write('Name of option is {}'.format(tabs))
|
99 |
|
100 |
elif tabs == 'Chat':
|
101 |
-
st.title("Chat Powered by Gemini")
|
102 |
st.write('Name of option is {}'.format(tabs))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
|
105 |
|
|
|
6 |
from datetime import datetime
|
7 |
from st_on_hover_tabs import on_hover_tabs
|
8 |
import streamlit as st
|
9 |
+
import os
|
10 |
+
from pandasai.llm import GoogleGemini
|
11 |
+
from pandasai import SmartDataframe
|
12 |
+
from pandasai.responses.response_parser import ResponseParser
|
13 |
+
|
14 |
st.set_page_config(layout="wide")
|
15 |
|
16 |
+
class StreamLitResponse(ResponseParser):
|
17 |
+
def __init__(self,context) -> None:
|
18 |
+
super().__init__(context)
|
19 |
+
def format_dataframe(self,result):
|
20 |
+
st.dataframe(result['value'])
|
21 |
+
return
|
22 |
+
def format_plot(self,result):
|
23 |
+
st.image(result['value'])
|
24 |
+
return
|
25 |
+
def format_other(self, result):
|
26 |
+
st.write(result['value'])
|
27 |
+
return
|
28 |
+
|
29 |
+
gemini_api_key = os.environ['Gemini']
|
30 |
+
|
31 |
+
def generateResponse(dataFrame,prompt):
|
32 |
+
llm = GoogleGemini(api_key=gemini_api_key)
|
33 |
+
pandas_agent = SmartDataframe(dataFrame,config={"llm":llm, "response_parser":StreamLitResponse})
|
34 |
+
answer = pandas_agent.chat(prompt)
|
35 |
+
return answer
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
# Initialize Firebase app
|
40 |
if not firebase_admin._apps:
|
41 |
cred = credentials.Certificate("ecomplaintbook-firebase-adminsdk-4q5bo-1f83312d02.json")
|
|
|
43 |
|
44 |
db = firestore.client()
|
45 |
|
46 |
+
complaints_ref = db.collection('complaints')
|
47 |
+
|
48 |
+
complaints_list = []
|
49 |
+
for doc in complaints_ref.stream():
|
50 |
+
a = doc.to_dict()
|
51 |
+
complaints_list.append(a)
|
52 |
+
|
53 |
+
complaints_df = pd.DataFrame(complaints_list)
|
54 |
|
55 |
# Function to fetch user profile from Firebase
|
56 |
def fetch_user_profile_from_firebase(user_id):
|
|
|
118 |
st.title("Navigation Bar")
|
119 |
st.header("Complaints")
|
120 |
# Then query to list all users
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
|
|
122 |
|
123 |
st.dataframe(complaints_df)
|
124 |
|
|
|
127 |
st.write('Name of option is {}'.format(tabs))
|
128 |
|
129 |
elif tabs == 'Chat':
|
130 |
+
st.title("eThekwini Chat Powered by Gemini")
|
131 |
st.write('Name of option is {}'.format(tabs))
|
132 |
+
|
133 |
+
|
134 |
+
# Display the data
|
135 |
+
with st.expander("Preview"):
|
136 |
+
st.write(df.head())
|
137 |
+
|
138 |
+
# Plot the data
|
139 |
+
user_input = st.text_input("Type your message here",placeholder="Ask me about complaints from eThekwini residents")
|
140 |
+
if user_input:
|
141 |
+
answer = generateResponse(dataFrame=complaints_df,prompt=user_input)
|
142 |
+
st.write(answer)
|
143 |
|
144 |
|
145 |
|