import google.generativeai as palm import pandas as pd import io from flask import Flask, request, jsonify from langchain.chains.question_answering import load_qa_chain from langchain import PromptTemplate, LLMChain from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent from langchain.chat_models import ChatOpenAI from langchain.agents.agent_types import AgentType from langchain.chat_models import ChatOpenAI import pandas as pd from langchain.llms import OpenAI from dotenv import load_dotenv import google.generativeai as palm from langchain.llms import GooglePalm import json from dotenv import load_dotenv load_dotenv() app = Flask(__name__) @app.route("/", methods=["GET"]) def home(): return "Hello Qx!" @app.route("/predict", methods=["POST"]) def bot(): load_dotenv() # json_table = request.json.get("json_table") user_question = request.json.get("user_question") df = pd.DataFrame(json_table) #df['Profit'] = df['Profit'].apply(lambda x: "R{:.1f}".format((x))) #df['Revenue'] = df['Revenue'].apply(lambda x: "R{:.1f}".format((x))) #llm = ChatOpenAI(model_name='gpt-3.5-turbo-0613', temperature=0, openai_api_key=os.getenv('OPENAI_API_KEY')) llm = GooglePalm(temperature=0, google_api_key=os.environ['PALM']) #agent = create_pandas_dataframe_agent(llm, df, verbose=True, agent_type=AgentType.OPENAI_FUNCTIONS) agent = create_pandas_dataframe_agent(llm, df, agent="structured_chat-zero-shot-react-description", verbose=True) response = agent.run(user_question) return jsonify(response) if __name__ == "__main__": app.run(debug=True,host="0.0.0.0", port=7860)