measmonysuon commited on
Commit
60d0daf
1 Parent(s): 92f9409

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -76,7 +76,14 @@ def get_user_points(user_chat_id):
76
  except requests.RequestException as e:
77
  logger.error(f"Error retrieving user points: {e}")
78
  return "Error retrieving points"
79
-
 
 
 
 
 
 
 
80
  def notify_webhook(user_chat_id):
81
  """Notify the webhook server about the points update."""
82
  webhook_url = f"{webhook_server}/notify_update"
@@ -135,13 +142,12 @@ def create_gradio_interface(user_chat_id):
135
  user_chat_id_input = gr.Textbox(
136
  label="User Chat ID",
137
  placeholder="Enter your user chat ID here...",
138
- value=user_chat_id,
139
- # interactive=False # Make the textbox non-editable
140
  )
141
  points_output = gr.Textbox(label="User Points", placeholder="User points will be displayed here")
142
 
143
  # Create the button to get user points
144
- get_points_button = gr.Button("Get Your Points")
145
 
146
  # Create other components
147
  prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
@@ -169,6 +175,12 @@ def create_gradio_interface(user_chat_id):
169
  outputs=[result_output, message_output]
170
  )
171
 
 
 
 
 
 
 
172
  gr.HTML("""
173
  <style>
174
  footer.svelte-1rjryqp {
 
76
  except requests.RequestException as e:
77
  logger.error(f"Error retrieving user points: {e}")
78
  return "Error retrieving points"
79
+
80
+ def retrieve_user_points(user_chat_id):
81
+ """Retrieve user points and display them."""
82
+ points = get_user_points(user_chat_id)
83
+ if points == "User not found":
84
+ return "Please register with @myexpsupportBot", ""
85
+ return f"Your current points: {points}", points
86
+
87
  def notify_webhook(user_chat_id):
88
  """Notify the webhook server about the points update."""
89
  webhook_url = f"{webhook_server}/notify_update"
 
142
  user_chat_id_input = gr.Textbox(
143
  label="User Chat ID",
144
  placeholder="Enter your user chat ID here...",
145
+ value=user_chat_id
 
146
  )
147
  points_output = gr.Textbox(label="User Points", placeholder="User points will be displayed here")
148
 
149
  # Create the button to get user points
150
+ get_points_button = gr.Button("Retrieve Your Points")
151
 
152
  # Create other components
153
  prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
 
175
  outputs=[result_output, message_output]
176
  )
177
 
178
+ get_points_button.click(
179
+ fn=retrieve_user_points,
180
+ inputs=[user_chat_id_input],
181
+ outputs=[points_output, points_output] # Display points in the same textbox
182
+ )
183
+
184
  gr.HTML("""
185
  <style>
186
  footer.svelte-1rjryqp {