h-siyuan commited on
Commit
48e54f1
·
verified ·
1 Parent(s): eea65c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -75,13 +75,10 @@ def upload_to_s3(file_name, bucket, object_name=None):
75
 
76
  try:
77
  s3.upload_file(file_name, bucket, object_name)
78
- # print(f"Uploaded {file_name} to {bucket}/{object_name}.")
79
  return True
80
  except FileNotFoundError:
81
- # print(f"The file {file_name} was not found.")
82
  return False
83
  except NoCredentialsError:
84
- # print("Credentials not available.")
85
  return False
86
 
87
  @spaces.GPU
@@ -129,7 +126,6 @@ def run_showui(image, query, session_id):
129
  def save_and_upload_data(image_path, query, session_id, is_example_image, votes=None):
130
  """Save the data to a JSON file and upload to S3."""
131
  if is_example_image:
132
- # print("Example image used. Skipping upload.")
133
  return
134
 
135
  votes = votes or {"upvotes": 0, "downvotes": 0}
@@ -153,7 +149,6 @@ def save_and_upload_data(image_path, query, session_id, is_example_image, votes=
153
  def update_vote(vote_type, session_id, is_example_image):
154
  """Update the vote count and re-upload the JSON file."""
155
  if is_example_image:
156
- # print("Example image used. Skipping vote update.")
157
  return "Example image used. No vote recorded."
158
 
159
  local_file_name = f"{session_id}.json"
@@ -227,9 +222,10 @@ def build_demo(embed_mode, concurrency_count=1):
227
  ["./examples/safari_google.png", "Click on search bar."],
228
  ]
229
 
230
- def set_example_flag(image_path, query):
 
231
  is_example = any(image_path == example[0] for example in examples)
232
- return image_path, query, is_example
233
 
234
  gr.Examples(
235
  examples=examples,
 
75
 
76
  try:
77
  s3.upload_file(file_name, bucket, object_name)
 
78
  return True
79
  except FileNotFoundError:
 
80
  return False
81
  except NoCredentialsError:
 
82
  return False
83
 
84
  @spaces.GPU
 
126
  def save_and_upload_data(image_path, query, session_id, is_example_image, votes=None):
127
  """Save the data to a JSON file and upload to S3."""
128
  if is_example_image:
 
129
  return
130
 
131
  votes = votes or {"upvotes": 0, "downvotes": 0}
 
149
  def update_vote(vote_type, session_id, is_example_image):
150
  """Update the vote count and re-upload the JSON file."""
151
  if is_example_image:
 
152
  return "Example image used. No vote recorded."
153
 
154
  local_file_name = f"{session_id}.json"
 
222
  ["./examples/safari_google.png", "Click on search bar."],
223
  ]
224
 
225
+ def set_example_flag(image, query):
226
+ image_path = image if isinstance(image, str) else None
227
  is_example = any(image_path == example[0] for example in examples)
228
+ return is_example
229
 
230
  gr.Examples(
231
  examples=examples,