measmonysuon commited on
Commit
084cc25
1 Parent(s): 4b91617

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -124,16 +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 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."
@@ -147,7 +147,23 @@ def gradio_interface(prompt, resolution_key, user_chat_id):
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."
 
 
 
 
150
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  def handle_generate_image(prompt, resolution_key, user_chat_id):
152
  points = get_user_points(user_chat_id)
153
  if isinstance(points, str):
 
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_url):
128
  webhook_url = f"{webhook_server}/notify_image"
129
+ payload = {'user_chat_id': user_chat_id, 'file_path': file_url}
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 URL: {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."
 
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."
150
+ '''
151
+ def gradio_interface(prompt, resolution_key, user_chat_id):
152
+ if not user_chat_id.strip():
153
+ return None, "User Chat ID cannot be blank. Please provide a valid User Chat ID."
154
 
155
+ result = generate_image(prompt, resolution_key)
156
+ if result and result[0]:
157
+ file_url = result[0][0].get('image') # Ensure this is a URL
158
+ if file_url and file_url.startswith('http'):
159
+ update_user_points(user_chat_id, -5)
160
+ notify_webhook_with_file(user_chat_id, file_url) # Notify webhook with file URL
161
+ return file_url, "The image was generated successfully."
162
+ return None, "The image URL is not available. Please try again later."
163
+ return None, "There was an error processing your photo. Please try again later."
164
+
165
+
166
+
167
  def handle_generate_image(prompt, resolution_key, user_chat_id):
168
  points = get_user_points(user_chat_id)
169
  if isinstance(points, str):