patrickvonplaten commited on
Commit
fc365d2
β€’
1 Parent(s): d109182
Files changed (2) hide show
  1. README.md +2 -1
  2. app.py +75 -131
README.md CHANGED
@@ -4,9 +4,10 @@ emoji: 🌍
4
  colorFrom: red
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 3.29.0
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
 
4
  colorFrom: red
5
  colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 3.41.0
8
  app_file: app.py
9
  pinned: false
10
+ duplicated_from: OpenGenAI/open-parti-prompts
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from datasets import load_dataset
2
  from collections import Counter, defaultdict
3
  from random import sample, shuffle
 
4
  import datasets
5
  from pandas import DataFrame
6
  from huggingface_hub import list_datasets
@@ -13,40 +14,41 @@ import secrets
13
  parti_prompt_results = []
14
  ORG = "diffusers-parti-prompts"
15
  SUBMISSIONS = {
16
- "sd-v1-5": load_dataset(os.path.join(ORG, "sd-v1-5"))["train"],
17
- "sd-v2-1": load_dataset(os.path.join(ORG, "sd-v2.1"))["train"],
18
- "if-v1-0": load_dataset(os.path.join(ORG, "karlo-v1"))["train"],
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
- SD_1_5_RESULT = """
30
- "## The traditional one πŸ”₯!
31
- ![img](https://huggingface.co/datasets/OpenGenAI/logos/resolve/main/37351293.png)
32
- \n You mostly resonate with **Stable Diffusion 1-5** released by RunwayML.
33
- \n Stable Diffusion 1-5 is the most used open-source text-to-image model offering an amazing speed-to-image-quality trade-off!
34
- \n Check out your soulmate [here](https://huggingface.co/runwayml/stable-diffusion-v1-5).
35
  """
36
- SD_2_1_RESULT = """
37
- ## The creative one 🎨!
38
  ![img](https://huggingface.co/datasets/OpenGenAI/logos/resolve/main/7vmYr2XwVcPtkLzac_jxQ.png)
39
- \n You mostly resonate with **Stable Diffusion 2-1** released by Stability AI.
40
- \n Stable Diffusion 2-1 is the latest open-source release of Stable Diffusion and allows to render stunning images of much larger sizes than Stable Diffusion v1.
41
- Try it out [here](https://huggingface.co/stabilityai/stable-diffusion-2-1).
 
42
  """
43
- IF_V1_0 = """
44
- ## The powerful one ⚑!
45
- ![img](https://huggingface.co/datasets/OpenGenAI/logos/resolve/main/1662453741854-63170739dc97a974718be2c7.png)
46
- \n You mostly resonate with **IF v1-0** released by DeepFloyd.
47
- \n IF v1-0 is by far the largest of the open-sourced text-to-image models and is a very powerful image generator.
48
- \n Besides being able to generate multiple complex concepts in the same image, IF v1-0 is also extremely good at generating text in images.
49
- \n Check out your new best friend [here](https://huggingface.co/DeepFloyd/IF-I-XL-v1.0).
 
50
  """
51
  KARLO = """
52
  ## The precise one 🎯!
@@ -57,15 +59,15 @@ KARLO = """
57
  """
58
 
59
  RESULT = {
60
- "sd-v1-5": SD_1_5_RESULT,
61
- "sd-v2-1": SD_2_1_RESULT,
62
- "if-v1-0": IF_V1_0,
63
  "karlo": KARLO,
64
  }
65
  NUM_QUESTIONS = 10
66
  MODEL_KEYS = "-".join(SUBMISSIONS.keys())
67
  SUBMISSION_ORG = f"results-{MODEL_KEYS}"
68
- PROMPT_FORMAT = " Pick the picture that best matches the prompt:"
69
 
70
  submission_names = list(SUBMISSIONS.keys())
71
  num_images = len(SUBMISSIONS[submission_names[0]])
@@ -161,31 +163,40 @@ def start():
161
 
162
  def process(dataframe, row_number=0):
163
  if row_number == NUM_QUESTIONS:
164
- return None, None, None, None, "", ""
 
 
165
 
166
  image_id = dataframe.iloc[row_number]["id"]
167
  choices = [
168
  submission_names[dataframe.iloc[row_number][f"choice_{i}"]]
169
  for i in range(len(SUBMISSIONS))
170
  ]
171
- images = (SUBMISSIONS[c][int(image_id)]["images"] for c in choices)
172
 
173
  prompt = SUBMISSIONS[choices[0]][int(image_id)]["Prompt"]
174
  prompt = f'# "{prompt}"'
175
  counter = f"***{row_number + 1}/{NUM_QUESTIONS} {PROMPT_FORMAT}***"
 
176
 
177
- return *images, prompt, counter
178
 
179
 
180
  def write_result(user_choice, row_number, dataframe):
181
  if row_number == NUM_QUESTIONS:
182
  return row_number, dataframe
183
 
184
- user_choice = int(user_choice)
185
- chosen_model = submission_names[dataframe.iloc[row_number][f"choice_{user_choice}"]]
 
 
 
 
 
 
186
 
187
- dataframe.loc[row_number, "result"] = chosen_model
188
- print(row_number)
189
  return row_number + 1, dataframe
190
 
191
 
@@ -196,7 +207,10 @@ def get_index(evt: gr.SelectData) -> int:
196
  def change_view(row_number, dataframe):
197
  if row_number == NUM_QUESTIONS:
198
 
199
- favorite_model = dataframe["result"].value_counts().idxmax()
 
 
 
200
  dataset = datasets.Dataset.from_pandas(dataframe)
201
  dataset = dataset.remove_columns(set(dataset.column_names) - set(["id", "result"]))
202
  hash = generate_random_hash()
@@ -225,7 +239,7 @@ TITLE = "# What AI model is best for you? πŸ‘©β€βš•οΈ"
225
  DESCRIPTION = """
226
  ***How it works*** πŸ“– \n\n
227
  - Upon clicking start, you are shown image descriptions alongside four AI generated images.
228
- \n- Select the image that best fits the image description.
229
  \n- Answer **10** questions to find out what AI generator most resonates with you.
230
  \n- Your submissions contribute to [**Open Parti Prompts Leaderboard**](https://huggingface.co/spaces/OpenGenAI/parti-prompts-leaderboard) ❀️.
231
  \n\n
@@ -236,11 +250,11 @@ The prompts you are shown originate from the [Parti Prompts](https://huggingface
236
  Parti Prompts is designed to test text-to-image AI models on 1600+ prompts of varying difficulty and categories.
237
  The images you are shown have been pre-generated with 4 state-of-the-art open-sourced text-to-image models.
238
  You answers will be used to contribute to the official [**Open Parti Prompts Leaderboard**](https://huggingface.co/spaces/OpenGenAI/parti-prompts-leaderboard).
239
- Every month, the generated images will be updated with possibly improved models. The current models and code that was used to generate the images can be verified here:\n
240
- - [sd-v1-5](https://huggingface.co/datasets/diffusers-parti-prompts/sd-v1-5) \n
241
- - [sd-v2.1](https://huggingface.co/datasets/diffusers-parti-prompts/sd-v2.1) \n
242
- - [if-v-1.0](https://huggingface.co/datasets/diffusers-parti-prompts/if-v-1.0) \n
243
- - [karlo-v1](https://huggingface.co/datasets/diffusers-parti-prompts/karlo-v1) \n
244
  """
245
 
246
  GALLERY_COLUMN_NUM = len(SUBMISSIONS)
@@ -293,16 +307,18 @@ with gr.Blocks() as demo:
293
  with gr.Row():
294
  with gr.Column() as c1:
295
  image_1 = gr.Image(interactive=False)
296
- image_1_button = gr.Button("Select 1").style(full_width=True)
297
  with gr.Column() as c2:
298
  image_2 = gr.Image(interactive=False)
299
- image_2_button = gr.Button("Select 2").style(full_width=True)
300
  with gr.Column() as c3:
301
  image_3 = gr.Image(interactive=False)
302
- image_3_button = gr.Button("Select 3").style(full_width=True)
303
  with gr.Column() as c4:
304
  image_4 = gr.Image(interactive=False)
305
- image_4_button = gr.Button("Select 4").style(full_width=True)
 
 
306
 
307
  start_button.click(
308
  fn=start,
@@ -316,92 +332,20 @@ with gr.Blocks() as demo:
316
  ).then(
317
  fn=change_view,
318
  inputs=[row_number, dataframe],
319
- outputs=[intro_view, result_view, gallery_view, start_view, result]
320
  ).then(
321
- fn=process, inputs=[dataframe], outputs=[image_1, image_2, image_3, image_4, prompt, counter]
 
 
322
  )
323
 
324
- image_1_button.click(
325
- fn=lambda: 0,
326
- inputs=[],
327
- outputs=[selected_image],
328
- ).then(
329
- fn=write_result,
330
- inputs=[selected_image, row_number, dataframe],
331
- outputs=[row_number, dataframe],
332
- ).then(
333
- fn=change_view,
334
- inputs=[row_number, dataframe],
335
- outputs=[intro_view, result_view, gallery_view, start_view, result]
336
- ).then(
337
- fn=process,
338
- inputs=[dataframe, row_number],
339
- outputs=[image_1, image_2, image_3, image_4, prompt, counter]
340
- ).then(
341
- fn=lambda x: 0 if x == NUM_QUESTIONS else x,
342
- inputs=[row_number],
343
- outputs=[row_number],
344
- ).then(
345
- fn=refresh,
346
- inputs=[row_number, dataframe],
347
- outputs=[dataframe],
348
- )
349
 
350
- image_2_button.click(
351
- fn=lambda: 1,
352
- inputs=[],
353
- outputs=[selected_image],
354
- ).then(
355
- fn=write_result,
356
- inputs=[selected_image, row_number, dataframe],
357
- outputs=[row_number, dataframe],
358
- ).then(
359
- fn=change_view,
360
- inputs=[row_number, dataframe],
361
- outputs=[intro_view, result_view, gallery_view, start_view, result]
362
- ).then(
363
- fn=process,
364
- inputs=[dataframe, row_number],
365
- outputs=[image_1, image_2, image_3, image_4, prompt, counter]
366
- ).then(
367
- fn=lambda x: 0 if x == NUM_QUESTIONS else x,
368
- inputs=[row_number],
369
- outputs=[row_number],
370
- ).then(
371
- fn=refresh,
372
- inputs=[row_number, dataframe],
373
- outputs=[dataframe],
374
- )
375
-
376
- image_3_button.click(
377
- fn=lambda: 2,
378
- inputs=[],
379
- outputs=[selected_image],
380
- ).then(
381
- fn=write_result,
382
- inputs=[selected_image, row_number, dataframe],
383
- outputs=[row_number, dataframe],
384
- ).then(
385
- fn=change_view,
386
- inputs=[row_number, dataframe],
387
- outputs=[intro_view, result_view, gallery_view, start_view, result]
388
- ).then(
389
- fn=process,
390
- inputs=[dataframe, row_number],
391
- outputs=[image_1, image_2, image_3, image_4, prompt, counter]
392
- ).then(
393
- fn=lambda x: 0 if x == NUM_QUESTIONS else x,
394
- inputs=[row_number],
395
- outputs=[row_number],
396
- ).then(
397
- fn=refresh,
398
- inputs=[row_number, dataframe],
399
- outputs=[dataframe],
400
- )
401
-
402
- image_4_button.click(
403
- fn=lambda: 3,
404
- inputs=[],
405
  outputs=[selected_image],
406
  ).then(
407
  fn=write_result,
@@ -414,7 +358,7 @@ with gr.Blocks() as demo:
414
  ).then(
415
  fn=process,
416
  inputs=[dataframe, row_number],
417
- outputs=[image_1, image_2, image_3, image_4, prompt, counter]
418
  ).then(
419
  fn=lambda x: 0 if x == NUM_QUESTIONS else x,
420
  inputs=[row_number],
 
1
  from datasets import load_dataset
2
  from collections import Counter, defaultdict
3
  from random import sample, shuffle
4
+ from collections import Counter
5
  import datasets
6
  from pandas import DataFrame
7
  from huggingface_hub import list_datasets
 
14
  parti_prompt_results = []
15
  ORG = "diffusers-parti-prompts"
16
  SUBMISSIONS = {
17
+ "kand2": load_dataset(os.path.join(ORG, "kandinsky-2-2"))["train"],
18
+ "sdxl": load_dataset(os.path.join(ORG, "sdxl-1.0-refiner"))["train"],
19
+ "wuerst": load_dataset(os.path.join(ORG, "wuerstchen"))["train"],
20
+ "karlo": load_dataset(os.path.join(ORG, "karlo-v1"))["train"],
 
21
  }
22
 
23
  LINKS = {
24
+ "kand2": "https://huggingface.co/kandinsky-community/kandinsky-2-2-decoder",
25
+ "sdxl": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0",
26
+ "wuerst": "https://huggingface.co/warp-ai/wuerstchen",
27
  "karlo": "https://huggingface.co/kakaobrain/karlo-v1-alpha",
28
  }
29
+ KANDINSKY = """
30
+ "## The creative one 🎨!
31
+ ![img](https://aeiljuispo.cloudimg.io/v7/https://cdn-uploads.huggingface.co/production/uploads/5dfcb1aada6d0311fd3d5448/rETvCyoUD5Mr9wm6OxUhe.png?w=200&h=200&f=face)
32
+ \n You mostly resonate with **Kandinsky 2.2** released by AI Forever.
33
+ \n Kandinsky 2.2 has a similar architecture to DALLE-2 and works extremely well for artistic, colorful generations.
34
+ \n Check out your soulmate [here](https://huggingface.co/kandinsky-community/kandinsky-2-2-decoder).
35
  """
36
+ SDXL_RESULT = """
37
+ ## The powerful one ⚑!
38
  ![img](https://huggingface.co/datasets/OpenGenAI/logos/resolve/main/7vmYr2XwVcPtkLzac_jxQ.png)
39
+ \n You mostly resonate with **Stable Diffusion XL** released by Stability AI.
40
+ \n Stable Diffusion XL consists of a two diffusion models that are chained together, a base model and a refiner model. Together, the system contains roughly 5 billion parameters.
41
+ \n It's the latest open-source release of Stable Diffusion and allows to render stunning images of much larger sizes than Stable Diffusion v1.
42
+ Try it out [here](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0).
43
  """
44
+ WUERSTCHEN = """
45
+ ## The innovative one βš—οΈ !
46
+ ![img](https://www.gravatar.com/avatar/3219846609129e84790fb83793998d61?d=retro&size=100)
47
+ \n You mostly resonate with **Wuerstchen** released by the WARP team.
48
+ \n Wuerstchen is a three stage diffusion model that proposed a very novel, innovative model architecture.
49
+ \n Wuerstchen is able to generate very large images (up to 1024x2048) in just a few seconds.
50
+ \n The model has an amazing image quality vs. speed trade-off.
51
+ \n Check out your new best friend [here](https://huggingface.co/warp-ai/wuerstchen).
52
  """
53
  KARLO = """
54
  ## The precise one 🎯!
 
59
  """
60
 
61
  RESULT = {
62
+ "kand2": KANDINSKY,
63
+ "wuerst": WUERSTCHEN,
64
+ "sdxl": SDXL_RESULT,
65
  "karlo": KARLO,
66
  }
67
  NUM_QUESTIONS = 10
68
  MODEL_KEYS = "-".join(SUBMISSIONS.keys())
69
  SUBMISSION_ORG = f"results-{MODEL_KEYS}"
70
+ PROMPT_FORMAT = " Select all pictures that correctly match the prompt and click on 'Submit'. Remember that if no image matches the prompt, no image shall be selected."
71
 
72
  submission_names = list(SUBMISSIONS.keys())
73
  num_images = len(SUBMISSIONS[submission_names[0]])
 
163
 
164
  def process(dataframe, row_number=0):
165
  if row_number == NUM_QUESTIONS:
166
+ nones = len(RESULT) * [None]
167
+ falses = len(RESULT) * [False]
168
+ return *nones, *falses, "", ""
169
 
170
  image_id = dataframe.iloc[row_number]["id"]
171
  choices = [
172
  submission_names[dataframe.iloc[row_number][f"choice_{i}"]]
173
  for i in range(len(SUBMISSIONS))
174
  ]
175
+ images = [SUBMISSIONS[c][int(image_id)]["images"] for c in choices]
176
 
177
  prompt = SUBMISSIONS[choices[0]][int(image_id)]["Prompt"]
178
  prompt = f'# "{prompt}"'
179
  counter = f"***{row_number + 1}/{NUM_QUESTIONS} {PROMPT_FORMAT}***"
180
+ image_buttons = len(images) * [False]
181
 
182
+ return *images, *image_buttons, prompt, counter
183
 
184
 
185
  def write_result(user_choice, row_number, dataframe):
186
  if row_number == NUM_QUESTIONS:
187
  return row_number, dataframe
188
 
189
+ user_choices = []
190
+ for i, b in enumerate(str(user_choice)):
191
+ if bool(int(b)):
192
+ user_choices.append(i)
193
+
194
+ chosen_models = []
195
+ for user_choice in user_choices:
196
+ chosen_models.append(submission_names[dataframe.iloc[row_number][f"choice_{user_choice}"]])
197
 
198
+ print(chosen_models)
199
+ dataframe.loc[row_number, "result"] = ",".join(chosen_models)
200
  return row_number + 1, dataframe
201
 
202
 
 
207
  def change_view(row_number, dataframe):
208
  if row_number == NUM_QUESTIONS:
209
 
210
+ results = sum([x.split(",") for x in dataframe["result"].values], [])
211
+ results = [r for r in results if len(r) > 0]
212
+ favorite_model = Counter(results).most_common(1)[0][0]
213
+
214
  dataset = datasets.Dataset.from_pandas(dataframe)
215
  dataset = dataset.remove_columns(set(dataset.column_names) - set(["id", "result"]))
216
  hash = generate_random_hash()
 
239
  DESCRIPTION = """
240
  ***How it works*** πŸ“– \n\n
241
  - Upon clicking start, you are shown image descriptions alongside four AI generated images.
242
+ \n- Select all images that match the prompt. **Note** that you should leave all images *unchecked* if no image matches the prompt.
243
  \n- Answer **10** questions to find out what AI generator most resonates with you.
244
  \n- Your submissions contribute to [**Open Parti Prompts Leaderboard**](https://huggingface.co/spaces/OpenGenAI/parti-prompts-leaderboard) ❀️.
245
  \n\n
 
250
  Parti Prompts is designed to test text-to-image AI models on 1600+ prompts of varying difficulty and categories.
251
  The images you are shown have been pre-generated with 4 state-of-the-art open-sourced text-to-image models.
252
  You answers will be used to contribute to the official [**Open Parti Prompts Leaderboard**](https://huggingface.co/spaces/OpenGenAI/parti-prompts-leaderboard).
253
+ Every couple months, the generated images will be updated with possibly improved models. The current models and code that was used to generate the images can be verified here:\n
254
+ - [kandinsky-2-2](https://huggingface.co/kandinsky-community/kandinsky-2-2-decoder) \n
255
+ - [wuerstchen](https://huggingface.co/warp-ai/wuerstchen) \n
256
+ - [sdxl-1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) \n
257
+ - [karlo](https://huggingface.co/datasets/diffusers-parti-prompts/karlo-v1) \n
258
  """
259
 
260
  GALLERY_COLUMN_NUM = len(SUBMISSIONS)
 
307
  with gr.Row():
308
  with gr.Column() as c1:
309
  image_1 = gr.Image(interactive=False)
310
+ image_1_button = gr.Checkbox(False, label="Image 1").style(full_width=True)
311
  with gr.Column() as c2:
312
  image_2 = gr.Image(interactive=False)
313
+ image_2_button = gr.Checkbox(False, label="Image 2").style(full_width=True)
314
  with gr.Column() as c3:
315
  image_3 = gr.Image(interactive=False)
316
+ image_3_button = gr.Checkbox(False, label="Image 3").style(full_width=True)
317
  with gr.Column() as c4:
318
  image_4 = gr.Image(interactive=False)
319
+ image_4_button = gr.Checkbox(False, label="Image 4").style(full_width=True)
320
+ with gr.Row():
321
+ submit_button = gr.Button("Submit").style(full_width=True)
322
 
323
  start_button.click(
324
  fn=start,
 
332
  ).then(
333
  fn=change_view,
334
  inputs=[row_number, dataframe],
335
+ outputs=[intro_view, result_view, gallery_view, start_view, result],
336
  ).then(
337
+ fn=process,
338
+ inputs=[dataframe],
339
+ outputs=[image_1, image_2, image_3, image_4, image_1_button, image_2_button, image_3_button, image_4_button, prompt, counter]
340
  )
341
 
342
+ def integerize(x1, x2, x3, x4):
343
+ number = f"{int(x1)}{int(x2)}{int(x3)}{int(x4)}"
344
+ return int(number)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
 
346
+ submit_button.click(
347
+ fn=integerize,
348
+ inputs=[image_1_button, image_2_button, image_3_button, image_4_button],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  outputs=[selected_image],
350
  ).then(
351
  fn=write_result,
 
358
  ).then(
359
  fn=process,
360
  inputs=[dataframe, row_number],
361
+ outputs=[image_1, image_2, image_3, image_4, image_1_button, image_2_button, image_3_button, image_4_button, prompt, counter],
362
  ).then(
363
  fn=lambda x: 0 if x == NUM_QUESTIONS else x,
364
  inputs=[row_number],