woters commited on
Commit
85a2ba5
β€’
1 Parent(s): 3d89119
Files changed (5) hide show
  1. README.md +4 -4
  2. app.py +221 -0
  3. qa_pairs.csv +8 -0
  4. requirements.txt +2 -0
  5. unlpboard_f.json +13 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Ddfd
3
- emoji: πŸ‘€
4
- colorFrom: gray
5
- colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 4.19.2
8
  app_file: app.py
 
1
  ---
2
+ title: Unlp
3
+ emoji: πŸŒ–
4
+ colorFrom: pink
5
+ colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 4.19.2
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import random
4
+ import firebase_admin
5
+ from firebase_admin import credentials
6
+ from firebase_admin import firestore
7
+
8
+ CSV_FILE_PATH = "qa_pairs.csv"
9
+
10
+ cred = credentials.Certificate("unlpboard_f.json")
11
+ firebase_admin.initialize_app(cred)
12
+
13
+ def list_models():
14
+ df = pd.read_csv(CSV_FILE_PATH)
15
+ return df['model'].unique().tolist()
16
+
17
+
18
+ def list_questions():
19
+ df = pd.read_csv(CSV_FILE_PATH)
20
+ return df['question'].unique().tolist()
21
+
22
+ def fetch_questions():
23
+ questions_ref = db.collection('questions')
24
+ docs = questions_ref.stream()
25
+ questions_list = []
26
+ for doc in docs:
27
+ question = doc.to_dict()
28
+ questions_list.append(question)
29
+ return questions_list
30
+
31
+
32
+ def display_answers(question, model1, model2):
33
+ df = pd.read_csv(CSV_FILE_PATH)
34
+ answers = {
35
+ model1: "No answer available for Model 1",
36
+ model2: "No answer available for Model 2",
37
+ }
38
+ for model in [model1, model2]:
39
+ filtered_df = df[(df['question'] == question) & (df['model'] == model)]
40
+ if not filtered_df.empty:
41
+ answers[model] = f"**{model} Answer:**\n{filtered_df['answer'].iloc[0]}"
42
+ return answers[model1], answers[model2]
43
+
44
+
45
+ def update_b(q,m1,a1,m2,a2):
46
+ print('Model1: ', random_model2)
47
+ print('Model2: ', random_model2)
48
+ q, m1, a1, m2, a2 = update_symbols(q, m1, a1, m2, a2)
49
+ b1 = gr.Button("Vote for Model 1",interactive=True)
50
+ b2 = gr.Button("It’s a tie!",interactive=True)
51
+ b3 = gr.Button("Vote for Model 2",interactive=True)
52
+ b4 = gr.Button("START!", visible = False)
53
+ return q, m1, a1, m2, a2, b1, b2, b3, b4
54
+
55
+
56
+ def update_symbols1(q,m1,a1,m2,a2):
57
+ print("Voted for Model 1")
58
+ log_vote(
59
+ model1=m1,
60
+ model2=m2,
61
+ question=q,
62
+ output1=a1,
63
+ output2=a2,
64
+ outcome=m1
65
+ )
66
+ votes_ref = db.collection('votes')
67
+ vote_doc = votes_ref.document(m1).get()
68
+ if vote_doc.exists:
69
+ votes_ref.document(m1).update({'count': firestore.Increment(1)})
70
+ else:
71
+ votes_ref.document(m1).set({'count': 1})
72
+ update_total_votes()
73
+ return update_symbols(q, m1, a1, m2, a2)
74
+
75
+
76
+ def update_symbols2(q, m1, a1, m2, a2):
77
+ print("Voted for Spare")
78
+ log_vote(
79
+ model1=m1,
80
+ model2=m2,
81
+ question=q,
82
+ output1=a1,
83
+ output2=a2,
84
+ outcome='tie'
85
+ )
86
+ update_total_votes()
87
+ return update_symbols(q, m1, a1, m2, a2)
88
+
89
+ def update_symbols3(q, m1, a1, m2, a2):
90
+ print("Voted for Model 2")
91
+ log_vote(
92
+ model1=m1,
93
+ model2=m2,
94
+ question=q,
95
+ output1=a1,
96
+ output2=a2,
97
+ outcome=m2
98
+ )
99
+ votes_ref = db.collection('votes')
100
+ vote_doc = votes_ref.document(m2).get()
101
+ if vote_doc.exists:
102
+ votes_ref.document(m2).update({'count': firestore.Increment(1)})
103
+ else:
104
+ votes_ref.document(m2).set({'count': 1})
105
+ update_total_votes()
106
+ return update_symbols(q, m1, a1, m2, a2)
107
+
108
+ def update_symbols(q,m1,a1,m2,a2):
109
+ random_question = random.choice(questions)
110
+ random_model1, random_model2 = random.sample(models, 2)
111
+ answer1, answer2 = display_answers(random_question, random_model1, random_model2)
112
+ m1 = gr.Markdown(f"{random_model1}", visible=False)
113
+ a1 = gr.Markdown(answer1)
114
+ q = gr.Markdown(f"{random_question}")
115
+ m2 = gr.Markdown(f"{random_model2}", visible=False)
116
+ a2 = gr.Markdown(answer2)
117
+ return q,m1,a1,m2,a2
118
+
119
+ def update_total_votes():
120
+ votes_ref = db.collection('votes')
121
+ vote_doc = votes_ref.document('total').get()
122
+ if vote_doc.exists:
123
+ votes_ref.document('total').update({'count': firestore.Increment(1)})
124
+ else:
125
+ votes_ref.document('total').set({'count': 1})
126
+
127
+ def log_vote(model1, model2, question, output1, output2, outcome):
128
+ # Reference to the Firestore collection where votes will be logged
129
+ votes_log_ref = db.collection('votes_log')
130
+
131
+ # Create a new document for this vote
132
+ vote_data = {
133
+ 'model1': model1,
134
+ 'model2': model2,
135
+ 'question': question,
136
+ 'output1': output1,
137
+ 'output2': output2,
138
+ 'outcome': outcome,
139
+ 'timestamp': firestore.SERVER_TIMESTAMP
140
+ }
141
+
142
+ # Add the vote document to Firestore
143
+ votes_log_ref.add(vote_data)
144
+
145
+
146
+ def fetch_and_format_leaderboard():
147
+ vote_counts_ref = db.collection('votes')
148
+ # Ensure you're using FieldPath.document_id() correctly
149
+ docs = vote_counts_ref.stream()
150
+
151
+ leaderboard = []
152
+ for doc in docs:
153
+ model_name = doc.id
154
+ vote_count = doc.to_dict().get('count', 0)
155
+ leaderboard.append(f"{model_name}: {vote_count} votes")
156
+
157
+ # Optional: Sort the leaderboard by vote count in descending order
158
+ leaderboard.sort(key=lambda x: int(x.split(': ')[1].split(' ')[0]), reverse=True)
159
+
160
+ return "\n".join(leaderboard)
161
+
162
+ #questions = list_questions()
163
+ models = list_models()
164
+ random_question = 'Click any button to start!'
165
+ random_model1, random_model2 = '1', '2'
166
+ answer1, answer2 = display_answers(random_question, random_model1, random_model2)
167
+
168
+
169
+ db = firestore.client()
170
+
171
+ questions = []
172
+ questions_ = fetch_questions()
173
+ for question in questions_:
174
+ questions.append(question['question_text'])
175
+
176
+ votes_ref = db.collection('votes')
177
+
178
+ def create_app():
179
+
180
+ print('-----------------------')
181
+ print(random_question)
182
+ print(random_model1)
183
+ print('-----!!!!!!!!!!!!!')
184
+
185
+ with gr.Blocks() as app:
186
+ q = gr.Markdown(f"### Question: {random_question}")
187
+
188
+ with gr.Row():
189
+ with gr.Column():
190
+ m1 = gr.Markdown(f"{random_model1}", visible=False)
191
+ a1 = gr.Markdown(answer1)
192
+
193
+ with gr.Column():
194
+ m2 = gr.Markdown(f"{random_model2}", visible=False)
195
+ a2 = gr.Markdown(answer2)
196
+
197
+ with gr.Row():
198
+ b1 = gr.Button("Vote for Model 1",interactive=False)
199
+ b2 = gr.Button("It’s a tie!",interactive=False)
200
+ b3 = gr.Button("Vote for Model 2",interactive=False)
201
+ with gr.Row():
202
+ b4 = gr.Button("START!", interactive=True)
203
+ #with gr.Row():
204
+ # b5 = gr.Button("Show Leaderboard")
205
+
206
+ initial_leaderboard_data = fetch_and_format_leaderboard()
207
+ leaderboard_display = gr.Textbox(value=initial_leaderboard_data,label="Leaderboard", placeholder="Leaderboard will be displayed here.",
208
+ lines=30, visible=True)
209
+ #b5.click(fn=fetch_and_format_leaderboard, inputs=[], outputs=leaderboard_display)
210
+
211
+ b4.click(update_b, inputs=[q,m1,a1,m2,a2], outputs=[q,m1,a1,m2,a2,b1,b2,b3, b4])
212
+ b1.click(update_symbols1, inputs=[q,m1,a1,m2,a2], outputs=[q,m1,a1,m2,a2])
213
+ b2.click(update_symbols2, inputs=[q, m1, a1, m2, a2], outputs=[q, m1, a1, m2, a2])
214
+ b3.click(update_symbols3, inputs=[q, m1, a1, m2, a2], outputs=[q, m1, a1, m2, a2])
215
+ leaderboard_button = gr.Button("Refresh Leaderboard")
216
+ leaderboard_button.click(fn=fetch_and_format_leaderboard, inputs=[], outputs=leaderboard_display)
217
+
218
+ return app
219
+
220
+ app = create_app()
221
+ app.launch()
qa_pairs.csv ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ question,answer,model
2
+ What is the capital of France?,Paris,Model A
3
+ What is the capital of France?,Brussels,Model B
4
+ What is the capital of France?,Kyiv,Model C
5
+ Who wrote '1984'?,George Orwell,Model A
6
+ What is the speed of light?,"Approximately 299,792 kilometers per second",Model B
7
+ What is the largest ocean?,Pacific Ocean,Model B
8
+ Who painted the Mona Lisa?,Leonardo da Vinci,Model C
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ firebase-admin
2
+ pandas
unlpboard_f.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "unlpboard",
4
+ "private_key_id": "cb34c2f851e6be6a6e1561c3cd5e3bb3492295b6",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGkeL/1Wa1KjeU\nGDM+qDPwn/gVsAZjXiIQPURVxPpOIiX4vEs4qfPSdOIPM5wX3bNZm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psJz5L9oUvfT9uH6qHYx+pLqXwuUI1O17Ttag+dNOkM0ZpwNnEIuvJZ2Bp\nZ8igfXHmdjeFDaCiLBhxUtgq9zQJdFdowGnglSD0acMxg21s7Q2iMPjvhQKBgQCe\nPWrmRPc+VguVW7kLyqj5EZKHacuQKAq344KjhG0APVMk1U3fThhAcPGB24/3gI6u\nl0qEUmfjXGsel5x2doAWIX6nGr7OPTxEb9AJvyIRE7uWIWifPXHS8knO+f4xAMuc\nu9V4pCw4qmjiFzzC757wpXNe3gKYxG/+IevB0ANU4QKBgQDUSPDmjItR0eFcfwN5\nAme5LpKHM5UsyW5Iq+P6prtYjvZlBUcCQzW9ukW+SGTDPBWdVl3f4NlcfnI0pCdv\ngo7fE8osBBxN81YigdtY50MXH8v0lZbt0PYNjz8wgDQ8iASTnMO2Kezouah5N7gB\ngMLcBMCeNTmPm8uvQL9U4PdvmQ==\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "firebase-adminsdk-bj4ah@unlpboard.iam.gserviceaccount.com",
7
+ "client_id": "103161232823398026076",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-bj4ah%40unlpboard.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }