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

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -16
main.py CHANGED
@@ -121,28 +121,28 @@ def process_user_msg(message, mobile):
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)
142
  if persist:
143
  # messenger.send_message(f"{response} \n\n {parsed_trans_data}", mobile)
144
  # Give user the chance to confirm/cancel transaction before processing other intents
145
- messenger_reply_button(mobile, f"Raw Response: {response}, \n \n Parsed Response: {parsed_trans_data}")
146
  else:
147
  messenger.send_message("Please try again!", mobile)
148
 
 
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"{response} \n\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)
142
  if persist:
143
  # messenger.send_message(f"{response} \n\n {parsed_trans_data}", mobile)
144
  # Give user the chance to confirm/cancel transaction before processing other intents
145
+ messenger_reply_button(mobile, f"{response} \n \n{parsed_trans_data}")
146
  else:
147
  messenger.send_message("Please try again!", mobile)
148