winglian commited on
Commit
2efc192
1 Parent(s): e81fd5d

send pref data to dynamo

Browse files

use partial to get label in

Files changed (2) hide show
  1. app.py +34 -4
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,14 +1,23 @@
1
  import concurrent
 
2
  import logging
3
  import os
4
  import re
 
 
5
  from time import sleep
6
 
 
7
  import gradio as gr
8
  import requests
9
 
10
  logging.basicConfig(level=os.getenv("LOG_LEVEL", "INFO"))
11
 
 
 
 
 
 
12
  class Pipeline:
13
  prefer_async = True
14
 
@@ -138,9 +147,29 @@ def chat(history1, history2, system_msg):
138
  sleep(0.15)
139
 
140
 
141
- def chosen_one(preferred_history, alt_history):
142
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
 
 
144
 
145
  with gr.Blocks() as arena:
146
  with gr.Row():
@@ -150,6 +179,7 @@ with gr.Blocks() as arena:
150
  - This Space runs on CPU only, and uses GGML with GPU support via Runpod Serverless.
151
  - Due to limitations of Runpod Serverless, it cannot stream responses immediately
152
  - Responses WILL take AT LEAST 30 seconds to respond, probably longer
 
153
  """)
154
  with gr.Tab("Chatbot"):
155
  with gr.Row():
@@ -205,7 +235,7 @@ with gr.Blocks() as arena:
205
  )
206
 
207
  choose1_click_event = choose1.click(
208
- fn=chosen_one, inputs=[chatbot1, chatbot2], outputs=[], queue=True
209
  ).then(
210
  lambda *args: (
211
  gr.update(visible=True, interactive=True),
@@ -220,7 +250,7 @@ with gr.Blocks() as arena:
220
  )
221
 
222
  choose2_click_event = choose2.click(
223
- fn=chosen_one, inputs=[chatbot2, chatbot1], outputs=[], queue=True
224
  ).then(
225
  lambda *args: (
226
  gr.update(visible=True, interactive=True),
 
1
  import concurrent
2
+ import functools
3
  import logging
4
  import os
5
  import re
6
+ import uuid
7
+ import datetime
8
  from time import sleep
9
 
10
+ import boto3
11
  import gradio as gr
12
  import requests
13
 
14
  logging.basicConfig(level=os.getenv("LOG_LEVEL", "INFO"))
15
 
16
+ # Create a DynamoDB client
17
+ dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
18
+ # Get a reference to the table
19
+ table = dynamodb.Table('oaaic_chatbot_arena')
20
+
21
  class Pipeline:
22
  prefer_async = True
23
 
 
147
  sleep(0.15)
148
 
149
 
150
+ def chosen_one(label, choice0_history, choice1_history, system_msg):
151
+ # Generate a uuid for each submission
152
+ arena_battle_id = str(uuid.uuid4())
153
+
154
+ # Get the current timestamp
155
+ timestamp = datetime.datetime.now().isoformat()
156
+
157
+ # Put the item in the table
158
+ table.put_item(
159
+ Item={
160
+ 'arena_battle_id': arena_battle_id,
161
+ 'timestamp': timestamp,
162
+ 'system_msg': system_msg,
163
+ 'choice0_name': model_hermes.name,
164
+ 'choice0': choice0_history,
165
+ 'choice1_name': model_manticore.name,
166
+ 'choice1': choice1_history,
167
+ 'label': label
168
+ }
169
+ )
170
 
171
+ chosen_one_first = functools.partial(chosen_one, 0)
172
+ chosen_one_second = functools.partial(chosen_one, 1)
173
 
174
  with gr.Blocks() as arena:
175
  with gr.Row():
 
179
  - This Space runs on CPU only, and uses GGML with GPU support via Runpod Serverless.
180
  - Due to limitations of Runpod Serverless, it cannot stream responses immediately
181
  - Responses WILL take AT LEAST 30 seconds to respond, probably longer
182
+ - For now, this is single turn only,
183
  """)
184
  with gr.Tab("Chatbot"):
185
  with gr.Row():
 
235
  )
236
 
237
  choose1_click_event = choose1.click(
238
+ fn=chosen_one_first, inputs=[chatbot1, chatbot2, system_msg], outputs=[], queue=True
239
  ).then(
240
  lambda *args: (
241
  gr.update(visible=True, interactive=True),
 
250
  )
251
 
252
  choose2_click_event = choose2.click(
253
+ fn=chosen_one_second, inputs=[chatbot1, chatbot2, system_msg], outputs=[], queue=True
254
  ).then(
255
  lambda *args: (
256
  gr.update(visible=True, interactive=True),
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  pyyaml
2
  requests
 
 
1
  pyyaml
2
  requests
3
+ boto3