Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -140,9 +140,6 @@ def run_showui(image, query):
|
|
140 |
# Modify the record_vote function
|
141 |
def record_vote(vote_type, image_path, query, action_generated, session_id):
|
142 |
"""Record a vote in a JSON file and upload to S3."""
|
143 |
-
if image_path is None:
|
144 |
-
return "No image uploaded. Please upload an image before voting."
|
145 |
-
|
146 |
vote_data = {
|
147 |
"vote_type": vote_type,
|
148 |
"image_path": image_path,
|
@@ -162,10 +159,12 @@ def record_vote(vote_type, image_path, query, action_generated, session_id):
|
|
162 |
|
163 |
return f"Your {vote_type} has been recorded. Thank you!"
|
164 |
|
|
|
165 |
def handle_vote(vote_type, image_path, query, action_generated, session_id):
|
166 |
"""Handle vote recording by using the consistent image path."""
|
167 |
-
|
168 |
-
|
|
|
169 |
|
170 |
# Load logo and encode to Base64
|
171 |
with open("./assets/showui.png", "rb") as image_file:
|
@@ -298,31 +297,31 @@ def build_demo(embed_mode, concurrency_count=1):
|
|
298 |
[output_img, output_coords],
|
299 |
)
|
300 |
|
301 |
-
#
|
302 |
vote_btn.click(
|
303 |
lambda image_path, query, action_generated, session_id: handle_vote(
|
304 |
"upvote", image_path, query, action_generated, session_id
|
305 |
),
|
306 |
inputs=[state_image_path, textbox, output_coords, state_session_id],
|
307 |
-
outputs=
|
308 |
queue=False
|
309 |
)
|
310 |
-
|
311 |
downvote_btn.click(
|
312 |
lambda image_path, query, action_generated, session_id: handle_vote(
|
313 |
"downvote", image_path, query, action_generated, session_id
|
314 |
),
|
315 |
inputs=[state_image_path, textbox, output_coords, state_session_id],
|
316 |
-
outputs=
|
317 |
queue=False
|
318 |
)
|
319 |
-
|
320 |
flag_btn.click(
|
321 |
lambda image_path, query, action_generated, session_id: handle_vote(
|
322 |
"flag", image_path, query, action_generated, session_id
|
323 |
),
|
324 |
inputs=[state_image_path, textbox, output_coords, state_session_id],
|
325 |
-
outputs=
|
326 |
queue=False
|
327 |
)
|
328 |
|
|
|
140 |
# Modify the record_vote function
|
141 |
def record_vote(vote_type, image_path, query, action_generated, session_id):
|
142 |
"""Record a vote in a JSON file and upload to S3."""
|
|
|
|
|
|
|
143 |
vote_data = {
|
144 |
"vote_type": vote_type,
|
145 |
"image_path": image_path,
|
|
|
159 |
|
160 |
return f"Your {vote_type} has been recorded. Thank you!"
|
161 |
|
162 |
+
# Use session_id in the handle_vote function
|
163 |
def handle_vote(vote_type, image_path, query, action_generated, session_id):
|
164 |
"""Handle vote recording by using the consistent image path."""
|
165 |
+
if image_path is None:
|
166 |
+
return "No image uploaded. Please upload an image before voting."
|
167 |
+
return record_vote(vote_type, image_path, query, action_generated, session_id)
|
168 |
|
169 |
# Load logo and encode to Base64
|
170 |
with open("./assets/showui.png", "rb") as image_file:
|
|
|
297 |
[output_img, output_coords],
|
298 |
)
|
299 |
|
300 |
+
# Record vote actions without feedback messages
|
301 |
vote_btn.click(
|
302 |
lambda image_path, query, action_generated, session_id: handle_vote(
|
303 |
"upvote", image_path, query, action_generated, session_id
|
304 |
),
|
305 |
inputs=[state_image_path, textbox, output_coords, state_session_id],
|
306 |
+
outputs=[],
|
307 |
queue=False
|
308 |
)
|
309 |
+
|
310 |
downvote_btn.click(
|
311 |
lambda image_path, query, action_generated, session_id: handle_vote(
|
312 |
"downvote", image_path, query, action_generated, session_id
|
313 |
),
|
314 |
inputs=[state_image_path, textbox, output_coords, state_session_id],
|
315 |
+
outputs=[],
|
316 |
queue=False
|
317 |
)
|
318 |
+
|
319 |
flag_btn.click(
|
320 |
lambda image_path, query, action_generated, session_id: handle_vote(
|
321 |
"flag", image_path, query, action_generated, session_id
|
322 |
),
|
323 |
inputs=[state_image_path, textbox, output_coords, state_session_id],
|
324 |
+
outputs=[],
|
325 |
queue=False
|
326 |
)
|
327 |
|