patrickvonplaten commited on
Commit
d9187eb
β€’
1 Parent(s): 273867b
Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +45 -21
__pycache__/app.cpython-310.pyc CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
 
app.py CHANGED
@@ -19,9 +19,17 @@ SUBMISSIONS = {
19
  "karlo": load_dataset(os.path.join(ORG, "if-v-1.0"))["train"],
20
  # "Kadinsky":
21
  }
 
 
 
 
 
 
 
22
  NUM_QUESTIONS = 10
23
  MODEL_KEYS = "-".join(SUBMISSIONS.keys())
24
  SUBMISSION_ORG = f"results-{MODEL_KEYS}"
 
25
 
26
 
27
  submission_names = list(SUBMISSIONS.keys())
@@ -106,7 +114,7 @@ def start():
106
 
107
  def process(dataframe, row_number=0):
108
  if row_number == NUM_QUESTIONS:
109
- return None, ""
110
 
111
  image_id = dataframe.iloc[row_number]["id"]
112
  choices = [
@@ -116,12 +124,13 @@ def process(dataframe, row_number=0):
116
  images = [SUBMISSIONS[c][int(image_id)]["images"] for c in choices]
117
 
118
  prompt = SUBMISSIONS[choices[0]][int(image_id)]["Prompt"]
119
- prompt = f"Prompt {row_number + 1}/{NUM_QUESTIONS}: '{prompt}'"
 
120
 
121
- return images, prompt
122
 
123
 
124
- def write_result(user_choice, row_number, dataframe, prompt):
125
  if row_number == NUM_QUESTIONS:
126
  return row_number, dataframe
127
 
@@ -147,31 +156,46 @@ def change_view(row_number, dataframe):
147
 
148
  dataset.push_to_hub(repo_id, token=os.getenv("HF_TOKEN"))
149
  return {
150
- result: f"You are of type: {favorite_model}!",
151
  result_view: gr.update(visible=True),
152
  gallery_view: gr.update(visible=False),
 
153
  }
154
  else:
155
  return {
156
- result: "",
157
  result_view: gr.update(visible=False),
158
  gallery_view: gr.update(visible=True),
 
159
  }
160
 
161
 
162
  if True:
163
- TITLE = "Community Parti Prompts - Who is your open-source genAI model?"
164
  DESCRIPTION = """
165
- An interactive game in which you click through pre-generated images from SD-v1-5, SD-v2.1, Karlo, and IF
166
- using [Parti Prompts](https://huggingface.co/datasets/nateraw/parti-prompts) prompts.
167
- You choices will go into the public community [genAI leaderboard](TODO)
168
  """
 
 
 
 
 
 
 
 
 
 
169
  GALLERY_COLUMN_NUM = len(SUBMISSIONS)
170
 
171
  with gr.Blocks(css="style.css") as demo:
172
  gr.Markdown(TITLE)
173
  gr.Markdown(DESCRIPTION)
174
- start_button = gr.Button("Start").style(full_width=False)
 
 
 
175
 
176
  headers = ["prompt", "result", "id", "Challenge", "Category", "Note"] + [
177
  f"choice_{i}" for i in range(len(SUBMISSIONS))
@@ -200,13 +224,12 @@ if True:
200
  )
201
  gr.Markdown("Click on start to play again!")
202
 
203
- with gr.Column(visible=True) as gallery_view:
204
- gr.Markdown("Pick your the photo that best corresponds to the prompt.")
205
- prompt = gr.Markdown(f"Prompt 1/{NUM_QUESTIONS}: ")
206
  gallery = gr.Gallery(
207
  label="All images", show_label=False, elem_id="gallery"
208
  ).style(columns=GALLERY_COLUMN_NUM, object_fit="contain")
209
-
210
  next_button = gr.Button("Select").style(full_width=False)
211
 
212
  with gr.Column(visible=False):
@@ -215,7 +238,8 @@ if True:
215
  start_button.click(
216
  fn=start,
217
  inputs=[],
218
- outputs=dataframe
 
219
  ).then(
220
  fn=lambda x: 0 if x == NUM_QUESTIONS else x,
221
  inputs=[row_number],
@@ -223,9 +247,9 @@ if True:
223
  ).then(
224
  fn=change_view,
225
  inputs=[row_number, dataframe],
226
- outputs=[result_view, gallery_view, result]
227
  ).then(
228
- fn=process, inputs=[dataframe], outputs=[gallery, prompt]
229
  )
230
 
231
  gallery.select(
@@ -236,16 +260,16 @@ if True:
236
 
237
  next_button.click(
238
  fn=write_result,
239
- inputs=[selected_image, row_number, dataframe, prompt],
240
  outputs=[row_number, dataframe],
241
  ).then(
242
  fn=change_view,
243
  inputs=[row_number, dataframe],
244
- outputs=[result_view, gallery_view, result]
245
  ).then(
246
  fn=process,
247
  inputs=[dataframe, row_number],
248
- outputs=[gallery, prompt]
249
  ).then(
250
  fn=lambda x: 0 if x == NUM_QUESTIONS else x,
251
  inputs=[row_number],
 
19
  "karlo": load_dataset(os.path.join(ORG, "if-v-1.0"))["train"],
20
  # "Kadinsky":
21
  }
22
+
23
+ LINKS = {
24
+ "sd-v1-5": "https://huggingface.co/runwayml/stable-diffusion-v1-5",
25
+ "sd-v2-1": "https://huggingface.co/stabilityai/stable-diffusion-2-1",
26
+ "if-v1-0": "https://huggingface.co/DeepFloyd/IF-I-XL-v1.0",
27
+ "karlo": "https://huggingface.co/kakaobrain/karlo-v1-alpha",
28
+ }
29
  NUM_QUESTIONS = 10
30
  MODEL_KEYS = "-".join(SUBMISSIONS.keys())
31
  SUBMISSION_ORG = f"results-{MODEL_KEYS}"
32
+ PROMPT_FORMAT = "Pick the picture that best matches the prompt: **{}**"
33
 
34
 
35
  submission_names = list(SUBMISSIONS.keys())
 
114
 
115
  def process(dataframe, row_number=0):
116
  if row_number == NUM_QUESTIONS:
117
+ return None, "", ""
118
 
119
  image_id = dataframe.iloc[row_number]["id"]
120
  choices = [
 
124
  images = [SUBMISSIONS[c][int(image_id)]["images"] for c in choices]
125
 
126
  prompt = SUBMISSIONS[choices[0]][int(image_id)]["Prompt"]
127
+ prompt = PROMPT_FORMAT.format(prompt)
128
+ counter = f"{row_number + 1}/{NUM_QUESTIONS}"
129
 
130
+ return images, prompt, counter
131
 
132
 
133
+ def write_result(user_choice, row_number, dataframe):
134
  if row_number == NUM_QUESTIONS:
135
  return row_number, dataframe
136
 
 
156
 
157
  dataset.push_to_hub(repo_id, token=os.getenv("HF_TOKEN"))
158
  return {
159
+ intro_view: gr.update(visible=True),
160
  result_view: gr.update(visible=True),
161
  gallery_view: gr.update(visible=False),
162
+ result: f"You are of type: [**{favorite_model}**]({LINKS[favorite_model]}) πŸ”₯",
163
  }
164
  else:
165
  return {
166
+ intro_view: gr.update(visible=False),
167
  result_view: gr.update(visible=False),
168
  gallery_view: gr.update(visible=True),
169
+ result: "",
170
  }
171
 
172
 
173
  if True:
174
+ TITLE = "# Community Parti Prompts - Who is your open-source genAI model?"
175
  DESCRIPTION = """
176
+ *This is an interactive game in which you click through pre-generated images from SD-v1-5, SD-v2.1, Karlo, and IF
177
+ using [Parti Prompts](https://huggingface.co/datasets/nateraw/parti-prompts) prompts.* \n
178
+ *You choices will go into the public community [genAI leaderboard](TODO).*
179
  """
180
+ EXPLANATION = """\n\n
181
+ ## How it works πŸ“– \n\n
182
+
183
+ 1. Click on 'Start'
184
+ 2. A prompt and 4 different images are displayed
185
+ 3. Select your favorite image
186
+ 4. Click on 'Select'
187
+ 5. After 10 rounds your favorite diffusion model is displayed
188
+ """
189
+
190
  GALLERY_COLUMN_NUM = len(SUBMISSIONS)
191
 
192
  with gr.Blocks(css="style.css") as demo:
193
  gr.Markdown(TITLE)
194
  gr.Markdown(DESCRIPTION)
195
+
196
+ with gr.Column(visible=True) as intro_view:
197
+ gr.Markdown(EXPLANATION)
198
+ start_button = gr.Button("Start").style(full_width=False)
199
 
200
  headers = ["prompt", "result", "id", "Challenge", "Category", "Note"] + [
201
  f"choice_{i}" for i in range(len(SUBMISSIONS))
 
224
  )
225
  gr.Markdown("Click on start to play again!")
226
 
227
+ with gr.Column(visible=False) as gallery_view:
228
+ counter = gr.Markdown(f" ### 1/{NUM_QUESTIONS}")
229
+ prompt = gr.Markdown(PROMPT_FORMAT.format(""))
230
  gallery = gr.Gallery(
231
  label="All images", show_label=False, elem_id="gallery"
232
  ).style(columns=GALLERY_COLUMN_NUM, object_fit="contain")
 
233
  next_button = gr.Button("Select").style(full_width=False)
234
 
235
  with gr.Column(visible=False):
 
238
  start_button.click(
239
  fn=start,
240
  inputs=[],
241
+ outputs=dataframe,
242
+ show_progress=True
243
  ).then(
244
  fn=lambda x: 0 if x == NUM_QUESTIONS else x,
245
  inputs=[row_number],
 
247
  ).then(
248
  fn=change_view,
249
  inputs=[row_number, dataframe],
250
+ outputs=[intro_view, result_view, gallery_view, result]
251
  ).then(
252
+ fn=process, inputs=[dataframe], outputs=[gallery, prompt, counter]
253
  )
254
 
255
  gallery.select(
 
260
 
261
  next_button.click(
262
  fn=write_result,
263
+ inputs=[selected_image, row_number, dataframe],
264
  outputs=[row_number, dataframe],
265
  ).then(
266
  fn=change_view,
267
  inputs=[row_number, dataframe],
268
+ outputs=[intro_view, result_view, gallery_view, result]
269
  ).then(
270
  fn=process,
271
  inputs=[dataframe, row_number],
272
+ outputs=[gallery, prompt, counter]
273
  ).then(
274
  fn=lambda x: 0 if x == NUM_QUESTIONS else x,
275
  inputs=[row_number],