|
import google.generativeai as palm |
|
import pandas as pd |
|
import os |
|
import io |
|
from flask import Flask, request, jsonify |
|
from flask_cors import CORS, cross_origin |
|
import pandas as pd |
|
import firebase_admin |
|
from firebase_admin import credentials, firestore, auth |
|
import streamlit as st |
|
import requests |
|
import pandas as pd |
|
from datetime import datetime |
|
from st_on_hover_tabs import on_hover_tabs |
|
import streamlit as st |
|
import os |
|
from pandasai.llm import GoogleGemini |
|
from pandasai import SmartDataframe |
|
from pandasai.responses.response_parser import ResponseParser |
|
import matplotlib.pyplot as plt |
|
from wordcloud import WordCloud |
|
import random |
|
|
|
from dotenv import load_dotenv |
|
import json |
|
|
|
|
|
from dotenv import load_dotenv |
|
|
|
load_dotenv() |
|
|
|
|
|
app = Flask(__name__) |
|
cors = CORS(app) |
|
|
|
@app.route("/", methods=["GET"]) |
|
def home(): |
|
|
|
return "Hello Qx!" |
|
|
|
|
|
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 |
|
|
|
|
|
if not firebase_admin._apps: |
|
|
|
cred = credentials.Certificate("ecomplaintbook-firebase-adminsdk-4q5bo-d27afe12f8.json") |
|
firebase_admin.initialize_app(cred) |
|
|
|
db = firestore.client() |
|
|
|
inventory_ref = db.collection('inventory') |
|
|
|
|
|
sales_ref = db.collection('sales') |
|
|
|
inventory_list = [] |
|
for doc in inventory_ref.stream(): |
|
a = doc.to_dict() |
|
inventory_list.append(a) |
|
|
|
sales_list = [] |
|
for doc in sales_ref.stream(): |
|
a = doc.to_dict() |
|
sales_list.append(a) |
|
|
|
inventory_df = pd.DataFrame(inventory_list) |
|
sales_df = pd.DataFrame(sales_list) |
|
|
|
|
|
|
|
@app.route("/predict", methods=["POST"]) |
|
@cross_origin() |
|
def bot(): |
|
load_dotenv() |
|
|
|
json_table = request.json.get("json_table") |
|
user_question = request.json.get("user_question") |
|
|
|
|
|
|
|
|
|
|
|
|
|
print(user_question) |
|
data = eval(str(json_table)) |
|
df = pd.DataFrame(data) |
|
print(list(df)) |
|
return jsonify(response) |
|
|
|
|
|
if __name__ == "__main__": |
|
app.run(debug=True,host="0.0.0.0", port=7860) |
|
|