measmonysuon commited on
Commit
6834783
1 Parent(s): ec175b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -124,6 +124,16 @@ def notify_webhook(user_chat_id):
124
  except requests.RequestException as e:
125
  logger.error(f"Error sending webhook notification: {e}")
126
 
 
 
 
 
 
 
 
 
 
 
127
  def gradio_interface(prompt, resolution_key, user_chat_id):
128
  if not user_chat_id.strip():
129
  return None, "User Chat ID cannot be blank. Please provide a valid User Chat ID."
@@ -133,6 +143,7 @@ def gradio_interface(prompt, resolution_key, user_chat_id):
133
  file_path = result[0][0].get('image')
134
  if file_path and os.path.exists(file_path):
135
  update_user_points(user_chat_id, -5)
 
136
  return file_path, "The image was generated successfully."
137
  return None, "The image file is not available. Please try again later."
138
  return None, "There was an error processing your photo. Please try again later."
 
124
  except requests.RequestException as e:
125
  logger.error(f"Error sending webhook notification: {e}")
126
 
127
+ def notify_webhook_with_file(user_chat_id, file_path):
128
+ webhook_url = f"{webhook_server}/notify_image"
129
+ payload = {'user_chat_id': user_chat_id, 'file_path': file_path}
130
+ try:
131
+ response = requests.post(webhook_url, json=payload)
132
+ response.raise_for_status()
133
+ logger.info(f"Webhook notification sent successfully for user {user_chat_id}. Response: {response.status_code}")
134
+ except requests.RequestException as e:
135
+ logger.error(f"Error sending webhook notification with file path: {e}")
136
+
137
  def gradio_interface(prompt, resolution_key, user_chat_id):
138
  if not user_chat_id.strip():
139
  return None, "User Chat ID cannot be blank. Please provide a valid User Chat ID."
 
143
  file_path = result[0][0].get('image')
144
  if file_path and os.path.exists(file_path):
145
  update_user_points(user_chat_id, -5)
146
+ notify_webhook_with_file(user_chat_id, file_path) # Notify webhook with file path
147
  return file_path, "The image was generated successfully."
148
  return None, "The image file is not available. Please try again later."
149
  return None, "There was an error processing your photo. Please try again later."