Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -2,7 +2,7 @@ import google.generativeai as palm
|
|
2 |
import pandas as pd
|
3 |
|
4 |
import io
|
5 |
-
from flask import Flask, request
|
6 |
from langchain.chains.question_answering import load_qa_chain
|
7 |
from langchain import PromptTemplate, LLMChain
|
8 |
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
|
@@ -33,6 +33,8 @@ def home():
|
|
33 |
def bot(json_table, user_question):
|
34 |
load_dotenv()
|
35 |
#
|
|
|
|
|
36 |
df = pd.DataFrame(json_table)
|
37 |
#df['Profit'] = df['Profit'].apply(lambda x: "R{:.1f}".format((x)))
|
38 |
#df['Revenue'] = df['Revenue'].apply(lambda x: "R{:.1f}".format((x)))
|
@@ -41,7 +43,7 @@ def bot(json_table, user_question):
|
|
41 |
#agent = create_pandas_dataframe_agent(llm, df, verbose=True, agent_type=AgentType.OPENAI_FUNCTIONS)
|
42 |
agent = create_pandas_dataframe_agent(llm, df, agent="structured_chat-zero-shot-react-description", verbose=True)
|
43 |
response = agent.run(user_question)
|
44 |
-
return response
|
45 |
|
46 |
|
47 |
if __name__ == "__main__":
|
|
|
2 |
import pandas as pd
|
3 |
|
4 |
import io
|
5 |
+
from flask import Flask, request, jsonify
|
6 |
from langchain.chains.question_answering import load_qa_chain
|
7 |
from langchain import PromptTemplate, LLMChain
|
8 |
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
|
|
|
33 |
def bot(json_table, user_question):
|
34 |
load_dotenv()
|
35 |
#
|
36 |
+
json_table = request.args.get("json_table")
|
37 |
+
user_question = request.args.get("user_question")
|
38 |
df = pd.DataFrame(json_table)
|
39 |
#df['Profit'] = df['Profit'].apply(lambda x: "R{:.1f}".format((x)))
|
40 |
#df['Revenue'] = df['Revenue'].apply(lambda x: "R{:.1f}".format((x)))
|
|
|
43 |
#agent = create_pandas_dataframe_agent(llm, df, verbose=True, agent_type=AgentType.OPENAI_FUNCTIONS)
|
44 |
agent = create_pandas_dataframe_agent(llm, df, agent="structured_chat-zero-shot-react-description", verbose=True)
|
45 |
response = agent.run(user_question)
|
46 |
+
return jsonify(response)
|
47 |
|
48 |
|
49 |
if __name__ == "__main__":
|