rairo commited on
Commit
05e9000
·
verified ·
1 Parent(s): db2ed86

Marketing tips feature

Browse files
Files changed (1) hide show
  1. main.py +30 -1
main.py CHANGED
@@ -18,7 +18,8 @@ from pandasai.responses.response_parser import ResponseParser
18
  import matplotlib.pyplot as plt
19
  from wordcloud import WordCloud
20
  import random
21
-
 
22
  from dotenv import load_dotenv
23
  import json
24
 
@@ -28,6 +29,8 @@ from dotenv import load_dotenv
28
  load_dotenv()
29
 
30
 
 
 
31
  app = Flask(__name__)
32
  cors = CORS(app)
33
 
@@ -119,6 +122,32 @@ def bot():
119
 
120
  return jsonify(resp)
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  if __name__ == "__main__":
124
  app.run(debug=True,host="0.0.0.0", port=7860)
 
18
  import matplotlib.pyplot as plt
19
  from wordcloud import WordCloud
20
  import random
21
+ from langchain.prompts import PromptTemplate
22
+ from langchain.chains import LLMChain
23
  from dotenv import load_dotenv
24
  import json
25
 
 
29
  load_dotenv()
30
 
31
 
32
+
33
+
34
  app = Flask(__name__)
35
  cors = CORS(app)
36
 
 
122
 
123
  return jsonify(resp)
124
 
125
+ @app.route("/mrec", methods=["POST"])
126
+ @cross_origin()
127
+ def marketing_rec():
128
+ user_id = request.json.get("user_id")
129
+
130
+ transactions_ref = db.collection("system_users").document(user_id).collection('transactions')
131
+ transactions_list = []
132
+ for doc in transactions_ref.stream():
133
+ a = doc.to_dict()
134
+ transactions_list.append(a)
135
+
136
+ transactions_df = pd.DataFrame(transactions_list)
137
+ # Set up a prompt template
138
+ prompt = PromptTemplate.from_template('You are a business analyst. Write some marketing tips suitable for a small mobile dashboard based on this transactions dataframe {data_frame}')
139
+
140
+ # Create a chain that utilizes both the LLM and the prompt template
141
+ chain = LLMChain(llm=llm, prompt=prompt, verbose=True)
142
+ data_frame = transactions_df
143
+ response = chain.invoke(input=data_frame)
144
+ print(response)
145
+
146
+ resp = str(response)
147
+
148
+ return jsonify(resp)
149
+
150
+
151
 
152
  if __name__ == "__main__":
153
  app.run(debug=True,host="0.0.0.0", port=7860)