Neurolingua commited on
Commit
e8772f1
1 Parent(s): 28bae9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -5,6 +5,8 @@ import os
5
  import requests
6
  from PIL import Image
7
  import io
 
 
8
  import uuid
9
  import shutil
10
  from other_function import predict_pest,predict_disease,convert_img,generate_response,ConversationBufferMemory,get_weather,get_rates
@@ -14,6 +16,11 @@ if not os.path.exists(UPLOAD_FOLDER):
14
  os.makedirs(UPLOAD_FOLDER)
15
 
16
  conversation_memory = ConversationBufferMemory(max_size=6)
 
 
 
 
 
17
 
18
  # Initialize the Flask app
19
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
@@ -67,8 +74,13 @@ def whatsapp_webhook():
67
  elif 'bookkeeping' in incoming_msg:
68
  response_text = "Please provide the details you'd like to record."
69
  elif ('rates' in incoming_msg.lower()) or ('price' in incoming_msg.lower()) or ('market' in incoming_msg.lower()) or ('rate' in incoming_msg.lower()) or ('prices' in incoming_msg.lower()):
70
- rate_data=get_rates()
71
- response_text=generate_response(incoming_msg+'data'+rate_data, chat_history)
 
 
 
 
 
72
 
73
  else:
74
  # Generate response considering the chat history
 
5
  import requests
6
  from PIL import Image
7
  import io
8
+ import threading
9
+
10
  import uuid
11
  import shutil
12
  from other_function import predict_pest,predict_disease,convert_img,generate_response,ConversationBufferMemory,get_weather,get_rates
 
16
  os.makedirs(UPLOAD_FOLDER)
17
 
18
  conversation_memory = ConversationBufferMemory(max_size=6)
19
+ def get_rates_async(callback):
20
+ def task():
21
+ result = get_rates()
22
+ callback(result)
23
+ threading.Thread(target=task).start()
24
 
25
  # Initialize the Flask app
26
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
 
74
  elif 'bookkeeping' in incoming_msg:
75
  response_text = "Please provide the details you'd like to record."
76
  elif ('rates' in incoming_msg.lower()) or ('price' in incoming_msg.lower()) or ('market' in incoming_msg.lower()) or ('rate' in incoming_msg.lower()) or ('prices' in incoming_msg.lower()):
77
+ def handle_rates(result):
78
+ response_text = generate_response(incoming_msg + ' data ' + result, chat_history)
79
+ conversation_memory.add_to_memory({"user": incoming_msg, "assistant": response_text})
80
+ send_message(sender, response_text)
81
+
82
+ get_rates_async(handle_rates)
83
+ return '', 204
84
 
85
  else:
86
  # Generate response considering the chat history