Sharfy commited on
Commit
4f9da92
·
1 Parent(s): 658aba2
Files changed (2) hide show
  1. README.md +2 -2
  2. app.py → bot.py +25 -5
README.md CHANGED
@@ -5,8 +5,8 @@ colorFrom: red
5
  colorTo: gray
6
  sdk: gradio
7
  sdk_version: 3.33.1
8
- app_file: app.py
9
- pinned: false
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
5
  colorTo: gray
6
  sdk: gradio
7
  sdk_version: 3.33.1
8
+ app_file: bot.py
9
+ pinned: true
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py → bot.py RENAMED
@@ -1,5 +1,5 @@
1
  import discord
2
- from discord import Option
3
  import redis
4
  import os
5
 
@@ -108,18 +108,37 @@ async def image(ctx, id):
108
  embed.set_image(url=path)
109
  await ctx.respond(embed=embed)
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  @bot.command(
112
  description="Label image observation",
113
  options=[
114
  Option(name="id", description="The ID of the image"),
115
  Option(name="label", description="The label for the image"),
116
- Option(name="confidence", description="The confidence for the label"),
117
  ])
118
- async def label_image(ctx, id:int, label:str, confidence:int):
119
  label_cnt = generate_id(f'label:{id}')
120
  r.hset(f'label:{id}:{label_cnt}'.encode('utf-8'), b'label', label.encode('utf-8'))
121
  r.hset(f'label:{id}:{label_cnt}'.encode('utf-8'), b'author', ctx.author.mention.encode('utf-8'))
122
- r.hset(f'label:{id}:{label_cnt}'.encode('utf-8'), b'confidence', ctx.author.mention.encode('utf-8'))
 
 
 
 
 
123
 
124
  # Fetch the image data from Redis
125
  image_data_bytes = r.hgetall(f'image:{id}'.encode('utf-8'))
@@ -132,7 +151,8 @@ async def label_image(ctx, id:int, label:str, confidence:int):
132
  embed.add_field(name="Sensor", value=image_data['sensor'], inline=True)
133
  embed.add_field(name="Label", value=image_data['label'], inline=True)
134
  embed.add_field(name="Proposed by", value=image_data['author'], inline=True)
135
- embed.set_image(url=image_data['path'])
 
136
 
137
  improve_player_stats(ctx)
138
 
 
1
  import discord
2
+ from discord import Option, commands
3
  import redis
4
  import os
5
 
 
108
  embed.set_image(url=path)
109
  await ctx.respond(embed=embed)
110
 
111
+ def confAutocomplete(self: discord.AutocompleteContext):
112
+ return ['low', 'medium', 'high']
113
+
114
+ def get_conf_score(confidence: str):
115
+ match confidence:
116
+ case "low":
117
+ return 0
118
+ case "medium":
119
+ return 1
120
+ case "high":
121
+ return 2
122
+ case _:
123
+ return 0
124
+
125
  @bot.command(
126
  description="Label image observation",
127
  options=[
128
  Option(name="id", description="The ID of the image"),
129
  Option(name="label", description="The label for the image"),
130
+ Option(name="confidence", description="Choose your confidence", autocomplete=confAutocomplete)
131
  ])
132
+ async def label_image(ctx, id:int, label:str, confidence: str):
133
  label_cnt = generate_id(f'label:{id}')
134
  r.hset(f'label:{id}:{label_cnt}'.encode('utf-8'), b'label', label.encode('utf-8'))
135
  r.hset(f'label:{id}:{label_cnt}'.encode('utf-8'), b'author', ctx.author.mention.encode('utf-8'))
136
+ conf_score = get_conf_score(confidence)
137
+ r.hset(f'label:{id}:{label_cnt}'.encode('utf-8'), b'confidence', conf_score)
138
+
139
+ r.hset(f'image:{id}'.encode('utf-8'), b'label', label.encode('utf-8'))
140
+ r.hset(f'image:{id}'.encode('utf-8'), b'author', ctx.author.mention.encode('utf-8'))
141
+
142
 
143
  # Fetch the image data from Redis
144
  image_data_bytes = r.hgetall(f'image:{id}'.encode('utf-8'))
 
151
  embed.add_field(name="Sensor", value=image_data['sensor'], inline=True)
152
  embed.add_field(name="Label", value=image_data['label'], inline=True)
153
  embed.add_field(name="Proposed by", value=image_data['author'], inline=True)
154
+ path = f'https://gainforest-transparency-dashboard.s3.amazonaws.com/{image_data["awsCID"]}'
155
+ embed.set_image(url=path)
156
 
157
  improve_player_stats(ctx)
158