daviddao commited on
Commit
3d58c56
·
1 Parent(s): 2605ea7

fixing issues

Browse files
Files changed (2) hide show
  1. bot.py +14 -6
  2. landing.md +1 -0
bot.py CHANGED
@@ -9,6 +9,7 @@ import gradio as gr
9
  from gradio import utils
10
  from pathlib import Path
11
 
 
12
  # Function to generate auto-incremented IDs
13
  def generate_id(key):
14
  return r.incr(key)
@@ -31,6 +32,11 @@ r = redis.from_url(redis_url)
31
 
32
  r.set('species_identified', 0)
33
 
 
 
 
 
 
34
  # def improve_player_stats_image(ctx):
35
  # # add 1 to the number of species identified
36
  # value = r.get(b'species_identified').decode('utf-8')
@@ -143,7 +149,7 @@ def get_conf_score(confidence: str):
143
  async def identify_image(ctx, id:int, label:str, confidence: str):
144
 
145
  timestamp = str(time.time())
146
- author_id = str(ctx.author_id)
147
 
148
  role = "Hobbyist"
149
  role_names = [role.name for role in ctx.author.roles]
@@ -213,7 +219,7 @@ async def sound(ctx, id): # a slash command will be created with the name "ping"
213
  async def identify_sound(ctx, id:int, label:str, timestamp:str, confidence: str):
214
 
215
  timestamp = str(time.time())
216
- author_id = str(ctx.author_id)
217
 
218
  role = "Hobbyist"
219
  role_names = [role.name for role in ctx.author.roles]
@@ -256,10 +262,12 @@ async def identify_sound(ctx, id:int, label:str, timestamp:str, confidence: str)
256
  )
257
  async def next_image(ctx):
258
  total_images = r.get(b'cnt:image').decode('utf-8')
259
- numbers = list(range(1, int(total_images)))
 
260
  exclude_redis = r.lrange('image:accept', 0, -1)
261
  exclude = set(int(num.decode('utf-8')) for num in exclude_redis)
262
  numbers = [num for num in numbers if num not in exclude]
 
263
  id = random.choice(numbers)
264
  await image(ctx, id)
265
 
@@ -268,11 +276,11 @@ async def next_image(ctx):
268
  )
269
  async def next_sound(ctx):
270
  total_sound = r.get(b'cnt:sound').decode('utf-8')
271
- numbers = list(range(1, int(total_sound)))
272
- exclude_redis = r.lrange('image:accept', 0, -1)
273
  exclude = set(int(num.decode('utf-8')) for num in exclude_redis)
274
  numbers = [num for num in numbers if num not in exclude]
275
- id = random.choice(numbers)
276
  await sound(ctx, id)
277
 
278
  @bot.command(
 
9
  from gradio import utils
10
  from pathlib import Path
11
 
12
+
13
  # Function to generate auto-incremented IDs
14
  def generate_id(key):
15
  return r.incr(key)
 
32
 
33
  r.set('species_identified', 0)
34
 
35
+ # Setup an exclusion list
36
+ with r.pipeline() as pipe:
37
+ pipe.rpush('image:accept', '0')
38
+ pipe.rpush('sound:accept', '0')
39
+
40
  # def improve_player_stats_image(ctx):
41
  # # add 1 to the number of species identified
42
  # value = r.get(b'species_identified').decode('utf-8')
 
149
  async def identify_image(ctx, id:int, label:str, confidence: str):
150
 
151
  timestamp = str(time.time())
152
+ author_id = str(ctx.author.id)
153
 
154
  role = "Hobbyist"
155
  role_names = [role.name for role in ctx.author.roles]
 
219
  async def identify_sound(ctx, id:int, label:str, timestamp:str, confidence: str):
220
 
221
  timestamp = str(time.time())
222
+ author_id = str(ctx.author.id)
223
 
224
  role = "Hobbyist"
225
  role_names = [role.name for role in ctx.author.roles]
 
262
  )
263
  async def next_image(ctx):
264
  total_images = r.get(b'cnt:image').decode('utf-8')
265
+ numbers = list(range(1, int(total_images) + 1))
266
+ print(total_images)
267
  exclude_redis = r.lrange('image:accept', 0, -1)
268
  exclude = set(int(num.decode('utf-8')) for num in exclude_redis)
269
  numbers = [num for num in numbers if num not in exclude]
270
+ print(numbers)
271
  id = random.choice(numbers)
272
  await image(ctx, id)
273
 
 
276
  )
277
  async def next_sound(ctx):
278
  total_sound = r.get(b'cnt:sound').decode('utf-8')
279
+ numbers = list(range(1, int(total_sound) + 1))
280
+ exclude_redis = r.lrange('sound:accept', 0, -1)
281
  exclude = set(int(num.decode('utf-8')) for num in exclude_redis)
282
  numbers = [num for num in numbers if num not in exclude]
283
+ id = random.choice(total_sound, numbers)
284
  await sound(ctx, id)
285
 
286
  @bot.command(
landing.md ADDED
@@ -0,0 +1 @@
 
 
1
+ ## XPRIZE Discord Bot