mrfakename commited on
Commit
3425a41
1 Parent(s): 5e2dd54
Files changed (1) hide show
  1. app.py +24 -14
app.py CHANGED
@@ -142,6 +142,12 @@ def create_db():
142
  upvote INTEGER,
143
  downvote INTEGER
144
  );
 
 
 
 
 
 
145
  ''')
146
 
147
  def get_data():
@@ -178,41 +184,45 @@ def get_data():
178
  # choice1 = get_random_split()
179
  # choice2 = get_random_split(choice1)
180
  # return (choice1, choice2)
181
- def upvote_model(model):
182
  conn = get_db()
183
  cursor = conn.cursor()
184
  cursor.execute('UPDATE model SET upvote = upvote + 1 WHERE name = ?', (model,))
185
  if cursor.rowcount == 0:
186
  cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 1, 0)', (model,))
 
187
  conn.commit()
188
  cursor.close()
189
- def downvote_model(model):
 
 
190
  conn = get_db()
191
  cursor = conn.cursor()
192
  cursor.execute('UPDATE model SET downvote = downvote + 1 WHERE name = ?', (model,))
193
  if cursor.rowcount == 0:
194
  cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 0, 1)', (model,))
 
195
  conn.commit()
196
  cursor.close()
197
- def a_is_better(model1, model2):
198
  if model1 and model2:
199
- upvote_model(model1)
200
- downvote_model(model2)
201
  return reload(model1, model2)
202
- def b_is_better(model1, model2):
203
  if model1 and model2:
204
- upvote_model(model2)
205
- downvote_model(model1)
206
  return reload(model1, model2)
207
- def both_bad(model1, model2):
208
  if model1 and model2:
209
- downvote_model(model1)
210
- downvote_model(model2)
211
  return reload(model1, model2)
212
- def both_good(model1, model2):
213
  if model1 and model2:
214
- upvote_model(model1)
215
- upvote_model(model2)
216
  return reload(model1, model2)
217
  def reload(chosenmodel1=None, chosenmodel2=None):
218
  # Select random splits
 
142
  upvote INTEGER,
143
  downvote INTEGER
144
  );
145
+ CREATE TABLE IF NOT EXISTS vote (
146
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
147
+ username TEXT,
148
+ model TEXT,
149
+ vote INTEGER
150
+ );
151
  ''')
152
 
153
  def get_data():
 
184
  # choice1 = get_random_split()
185
  # choice2 = get_random_split(choice1)
186
  # return (choice1, choice2)
187
+ def upvote_model(model, uname):
188
  conn = get_db()
189
  cursor = conn.cursor()
190
  cursor.execute('UPDATE model SET upvote = upvote + 1 WHERE name = ?', (model,))
191
  if cursor.rowcount == 0:
192
  cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 1, 0)', (model,))
193
+ cursor.execute('INSERT INTO vote (username, model, vote)', (uname, model, 1))
194
  conn.commit()
195
  cursor.close()
196
+
197
+
198
+ def downvote_model(model, uname):
199
  conn = get_db()
200
  cursor = conn.cursor()
201
  cursor.execute('UPDATE model SET downvote = downvote + 1 WHERE name = ?', (model,))
202
  if cursor.rowcount == 0:
203
  cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 0, 1)', (model,))
204
+ cursor.execute('INSERT INTO vote (username, model, vote)', (uname, model, -1))
205
  conn.commit()
206
  cursor.close()
207
+ def a_is_better(model1, model2, profile: gr.OAuthProfile | None):
208
  if model1 and model2:
209
+ upvote_model(model1, profile.username)
210
+ downvote_model(model2, profile.username)
211
  return reload(model1, model2)
212
+ def b_is_better(model1, model2, profile: gr.OAuthProfile | None):
213
  if model1 and model2:
214
+ upvote_model(model2, profile.username)
215
+ downvote_model(model1, profile.username)
216
  return reload(model1, model2)
217
+ def both_bad(model1, model2, profile: gr.OAuthProfile | None):
218
  if model1 and model2:
219
+ downvote_model(model1, profile.username)
220
+ downvote_model(model2, profile.username)
221
  return reload(model1, model2)
222
+ def both_good(model1, model2, profile: gr.OAuthProfile | None):
223
  if model1 and model2:
224
+ upvote_model(model1, profile.username)
225
+ upvote_model(model2, profile.username)
226
  return reload(model1, model2)
227
  def reload(chosenmodel1=None, chosenmodel2=None):
228
  # Select random splits