measmonysuon commited on
Commit
1563aef
1 Parent(s): 0277ed0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -117,32 +117,40 @@ def create_gradio_interface():
117
  # Create the button to get user points
118
  get_points_button = gr.Button("Get Points")
119
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  # Arrange user_chat_id_input, points_output, and get_points_button in one row
121
  with gr.Row():
122
  user_chat_id_input
123
  points_output
124
  get_points_button
125
 
126
- # Create other components
127
- prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
128
- resolution_dropdown = gr.Dropdown(choices=list(resolutions.keys()), label="Resolution", value="1024x1024")
129
- generate_button = gr.Button("Generate")
130
 
131
- result_output = gr.Image(label="Generated Image", type="pil")
132
- message_output = gr.Textbox(label="Result", placeholder="Results will be shown here", interactive=False)
 
 
 
 
133
 
134
- # Set up interaction
135
  generate_button.click(
136
  fn=lambda prompt, resolution_key, user_chat_id: gradio_interface(prompt, resolution_key, user_chat_id),
137
  inputs=[prompt_input, resolution_dropdown, user_chat_id_input],
138
  outputs=[result_output, message_output]
139
  )
140
-
141
- get_points_button.click(
142
- fn=lambda user_chat_id: get_user_points(user_chat_id),
143
- inputs=[user_chat_id_input],
144
- outputs=points_output
145
- )
146
 
147
  gr.HTML("""
148
  <style>
 
117
  # Create the button to get user points
118
  get_points_button = gr.Button("Get Points")
119
 
120
+ # Create a component for the button state
121
+ generate_button = gr.Button("Generate")
122
+ generate_button.style(height=40)
123
+
124
+ # Function to check points and enable/disable generate button
125
+ def check_points_and_update(user_chat_id):
126
+ points = get_user_points(user_chat_id)
127
+ if points == "Failed to retrieve user points":
128
+ return points, gr.Button("Generate", visible=False)
129
+ else:
130
+ return points, gr.Button("Generate", visible=points >= 5)
131
+
132
  # Arrange user_chat_id_input, points_output, and get_points_button in one row
133
  with gr.Row():
134
  user_chat_id_input
135
  points_output
136
  get_points_button
137
 
138
+ # Arrange generate_button in a separate row
139
+ with gr.Row():
140
+ generate_button
 
141
 
142
+ # Set up interactions
143
+ get_points_button.click(
144
+ fn=lambda user_chat_id: check_points_and_update(user_chat_id),
145
+ inputs=[user_chat_id_input],
146
+ outputs=[points_output, generate_button]
147
+ )
148
 
 
149
  generate_button.click(
150
  fn=lambda prompt, resolution_key, user_chat_id: gradio_interface(prompt, resolution_key, user_chat_id),
151
  inputs=[prompt_input, resolution_dropdown, user_chat_id_input],
152
  outputs=[result_output, message_output]
153
  )
 
 
 
 
 
 
154
 
155
  gr.HTML("""
156
  <style>