File size: 1,849 Bytes
b3a99ca 1a0d7ed 988c7cc af2645a 1791798 988c7cc 5f2f34f 988c7cc 5f2f34f 988c7cc 5f2f34f 988c7cc 5f2f34f 988c7cc 5f2f34f 40fbdfe 12ad28b e012855 12ad28b 1791798 4cc36bd 988c7cc 5f2f34f ee6c2b7 3c112ae cb1ffb7 3c112ae 0f71b02 2e9daa3 5f2f34f 658e438 b3f7202 658e438 74b00de 05b0fb5 988c7cc 96af30c |
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 55 56 57 58 59 60 61 62 |
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
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__)
cors = CORS(app)
@app.route("/", methods=["GET"])
def home():
return "Hello Qx!"
@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")
#data = request.get_json(force=True)TRye
#print(req_body)
#data = eval(req_body)
#json_table = data["json_table"]
#user_question = data["user_question"]
print(json_table)
print(user_question)
data = eval(json_table)
df = pd.DataFrame(data)
#df['Profit'] = df['Profit'].apply(lambda x: "R{:.1f}".format((x)))
#df['Revenue'] = df['Revenue'].apply(lambda x: "R{:.1f}".format((x)))
llm = GooglePalm(temperature=0, google_api_key=os.environ['PALM'])
agent = create_pandas_dataframe_agent(llm, df, agent="structured_chat-zero-shot-react-description", verbose=True)
response = agent.run(user_question)
#response.headers.add('Access-Control-Allow-Origin', '*')
return jsonify(response)
if __name__ == "__main__":
app.run(debug=True,host="0.0.0.0", port=7860)
|