williamagyapong commited on
Commit
ee22d8a
·
verified ·
1 Parent(s): c1dd32f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +17 -1
main.py CHANGED
@@ -10,6 +10,7 @@ from utility import generateResponse, parse_multiple_transactions, create_invent
10
  from google.cloud import firestore
11
  import ast
12
  import base64
 
13
 
14
 
15
  # load env data
@@ -119,7 +120,22 @@ def process_user_msg(message, mobile):
119
  intent = parsed_trans_data[0]['intent'].lower()
120
  if intent == 'read':
121
  response2 = str(read_datalake(mobile, message))
122
- messenger.send_message(f"*Raw Response*:\n {response}, \n \n *Parsed Response*:\n {parsed_trans_data}, \n \n *Final Response*:\n {response2}", recipient_id=mobile)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  else:
124
  # Persist transaction data temporarily for Create, Update, or Delete operations
125
  persist = persist_temporary_transaction(parsed_trans_data, mobile)
 
10
  from google.cloud import firestore
11
  import ast
12
  import base64
13
+ import requests
14
 
15
 
16
  # load env data
 
120
  intent = parsed_trans_data[0]['intent'].lower()
121
  if intent == 'read':
122
  response2 = str(read_datalake(mobile, message))
123
+ # Check if response is a string and represents a valid image path
124
+ if isinstance(response2, str) and os.path.isfile(os.path.join(response2)):
125
+ image_path = os.path.join(response2)
126
+ print("My image path:", image_path)
127
+ with open(image_path, "rb") as file:
128
+ data = file.read()
129
+ base64_data = base64.b64encode(data)
130
+
131
+ # Upload image to Imgur and get URL
132
+ response2 = requests.post(url, headers=headers, data={"image": base64_data})
133
+ url1= response2.json()["data"]["link"]
134
+ print(url1)
135
+
136
+ messenger.send_image(image=url1, recipient_id=mobile)
137
+ else:
138
+ messenger.send_message(f"*Raw Response*:\n {response}, \n \n *Parsed Response*:\n {parsed_trans_data}, \n \n *Final Response*:\n {response2}", recipient_id=mobile)
139
  else:
140
  # Persist transaction data temporarily for Create, Update, or Delete operations
141
  persist = persist_temporary_transaction(parsed_trans_data, mobile)