rairo commited on
Commit
06154c7
·
verified ·
1 Parent(s): 3b2b5ec

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +50 -0
main.py CHANGED
@@ -5,6 +5,21 @@ import io
5
  from flask import Flask, request, jsonify
6
  from flask_cors import CORS, cross_origin
7
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  from dotenv import load_dotenv
10
  import json
@@ -23,6 +38,41 @@ def home():
23
 
24
  return "Hello Qx!"
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  @app.route("/predict", methods=["POST"])
27
  @cross_origin()
28
  def bot():
 
5
  from flask import Flask, request, jsonify
6
  from flask_cors import CORS, cross_origin
7
  import pandas as pd
8
+ import firebase_admin
9
+ from firebase_admin import credentials, firestore, auth
10
+ import streamlit as st
11
+ import requests
12
+ import pandas as pd
13
+ from datetime import datetime
14
+ from st_on_hover_tabs import on_hover_tabs
15
+ import streamlit as st
16
+ import os
17
+ from pandasai.llm import GoogleGemini
18
+ from pandasai import SmartDataframe
19
+ from pandasai.responses.response_parser import ResponseParser
20
+ import matplotlib.pyplot as plt
21
+ from wordcloud import WordCloud
22
+ import random
23
 
24
  from dotenv import load_dotenv
25
  import json
 
38
 
39
  return "Hello Qx!"
40
 
41
+
42
+ def generateResponse(dataFrame,prompt):
43
+ llm = GoogleGemini(api_key=gemini_api_key)
44
+ pandas_agent = SmartDataframe(dataFrame,config={"llm":llm, "response_parser":StreamLitResponse})
45
+ answer = pandas_agent.chat(prompt)
46
+ return answer
47
+
48
+ # Initialize Firebase app
49
+ if not firebase_admin._apps:
50
+
51
+ cred = credentials.Certificate("ecomplaintbook-firebase-adminsdk-4q5bo-d27afe12f8.json")
52
+ firebase_admin.initialize_app(cred)
53
+
54
+ db = firestore.client()
55
+
56
+ inventory_ref = db.collection('inventory')
57
+
58
+
59
+ sales_ref = db.collection('sales')
60
+
61
+ inventory_list = []
62
+ for doc in inventory_ref.stream():
63
+ a = doc.to_dict()
64
+ inventory_list.append(a)
65
+
66
+ sales_list = []
67
+ for doc in sales_ref.stream():
68
+ a = doc.to_dict()
69
+ sales_list.append(a)
70
+
71
+ inventory_df = pd.DataFrame(inventory_list)
72
+ sales_df = pd.DataFrame(sales_list)
73
+
74
+
75
+
76
  @app.route("/predict", methods=["POST"])
77
  @cross_origin()
78
  def bot():