measmonysuon commited on
Commit
96b27af
1 Parent(s): da85c2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -82,10 +82,14 @@ def get_user_points(user_chat_id):
82
  try:
83
  response = requests.get(webhook_url, params=params)
84
  response.raise_for_status()
85
- return response.json().get('points', 0) # Default to 0 if points not found
 
 
 
 
86
  except requests.RequestException as e:
87
  logger.error(f"Error fetching user points: {e}")
88
- return 0
89
 
90
  def extract_user_chat_id_from_url(url):
91
  parsed_url = urlparse(url)
@@ -141,6 +145,12 @@ def create_gradio_interface(user_chat_id):
141
 
142
  def handle_generate_image(prompt, resolution_key, user_chat_id):
143
  points = get_user_points(user_chat_id)
 
 
 
 
 
 
144
  if points >= 5:
145
  result = gradio_interface(prompt, resolution_key, user_chat_id)
146
  if result[0]: # If image generation is successful
 
82
  try:
83
  response = requests.get(webhook_url, params=params)
84
  response.raise_for_status()
85
+ data = response.json()
86
+ if 'points' in data:
87
+ return data['points']
88
+ else:
89
+ return None # User not found or points not in response
90
  except requests.RequestException as e:
91
  logger.error(f"Error fetching user points: {e}")
92
+ return None
93
 
94
  def extract_user_chat_id_from_url(url):
95
  parsed_url = urlparse(url)
 
145
 
146
  def handle_generate_image(prompt, resolution_key, user_chat_id):
147
  points = get_user_points(user_chat_id)
148
+
149
+ # Check if user_chat_id is found in the database
150
+ if points is None:
151
+ return None, "User not found. Please register with @myexpsupportBot."
152
+
153
+ # Check if the user has enough points
154
  if points >= 5:
155
  result = gradio_interface(prompt, resolution_key, user_chat_id)
156
  if result[0]: # If image generation is successful