osanseviero commited on
Commit
250f62b
·
1 Parent(s): f04a6d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -67
app.py CHANGED
@@ -5,46 +5,38 @@ import gradio as gr
5
  import pandas as pd
6
  from huggingface_hub import HfApi, repocard
7
 
8
- def is_duplicated(space_id:str)->None:
9
- card = repocard.RepoCard.load(space_id, repo_type="space")
10
- return getattr(card.data, "duplicated_from", None) is not None
11
-
12
-
13
-
14
- def make_clickable_model(model_name, link=None):
15
- if link is None:
16
- link = "https://huggingface.co/" + "spaces/" + model_name
17
- return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
18
-
19
- def get_space_ids(category):
20
  api = HfApi()
21
- spaces = api.list_spaces(filter=["keras-dreambooth", category])
22
- print(spaces)
23
- space_ids = [x for x in spaces]
24
- return space_ids
25
-
26
-
27
- def make_clickable_user(user_id):
28
- link = "https://huggingface.co/" + user_id
29
- return f'<a target="_blank" href="{link}">{user_id}</a>'
30
-
31
- def get_submissions(category):
32
- submissions = get_space_ids(category)
33
- leaderboard_models = []
34
 
35
  for submission in submissions:
36
- # user, model, likes
37
- if not is_duplicated(submission.id):
38
- user_id = submission.id.split("/")[0]
39
- leaderboard_models.append(
40
- (
41
- make_clickable_user(user_id),
42
- make_clickable_model(submission.id),
43
- submission.likes,
44
- )
45
  )
 
46
 
47
- df = pd.DataFrame(data=leaderboard_models, columns=["User", "Space", "Likes"])
48
  df.sort_values(by=["Likes"], ascending=False, inplace=True)
49
  df.insert(0, "Rank", list(range(1, len(df) + 1)))
50
  return df
@@ -53,62 +45,45 @@ block = gr.Blocks()
53
 
54
  with block:
55
  gr.Markdown(
56
- """# Keras DreamBooth Leaderboard
57
-
58
- Welcome to the leaderboard for the Keras DreamBooth Event! This is a community event where participants **personalise a Stable Diffusion model** by fine-tuning it with a powerful technique called [_DreamBooth_](https://arxiv.org/abs/2208.12242). This technique allows one to implant a subject into the output domain of the model such that it can be synthesized with a _unique identifier_ in the prompt.
59
-
60
- This competition is composed of 4 _themes_, where each theme will collect models belong to one of the categories shown in the tabs below. We'll be **giving out prizes to the top 3 most liked models per theme**, and you're encouraged to submit as many models as you want!
61
-
62
  """
63
  )
64
  with gr.Tabs():
65
- with gr.TabItem("Nature 🐨 🌳 "):
66
  with gr.Row():
67
- nature_data = gr.components.Dataframe(
68
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
69
  )
70
  with gr.Row():
71
  data_run = gr.Button("Refresh")
72
  data_run.click(
73
- get_submissions, inputs=gr.Variable("nature"), outputs=nature_data
74
  )
75
- with gr.TabItem("Science Fiction & Fantasy 🧙‍♀️ 🧛‍♀️ 🤖 "):
76
  with gr.Row():
77
  scifi_data = gr.components.Dataframe(
78
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
79
  )
80
  with gr.Row():
81
  data_run = gr.Button("Refresh")
82
  data_run.click(
83
- get_submissions, inputs=gr.Variable("scifi"), outputs=scifi_data
84
  )
85
- with gr.TabItem("Consentful 🖼️ 🎨 "):
86
  with gr.Row():
87
  consentful_data = gr.components.Dataframe(
88
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
89
  )
90
  with gr.Row():
91
  data_run = gr.Button("Refresh")
92
  data_run.click(
93
- get_submissions, inputs=gr.Variable("consentful"), outputs=consentful_data
94
- )
95
- with gr.TabItem("Wild Card 🃏"):
96
- with gr.Row():
97
- wildcard_data = gr.components.Dataframe(
98
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
99
- )
100
- with gr.Row():
101
- data_run = gr.Button("Refresh")
102
- data_run.click(
103
- get_submissions,
104
- inputs=gr.Variable("wildcard"),
105
- outputs=wildcard_data,
106
  )
107
 
108
- block.load(get_submissions, inputs=gr.Variable("nature"), outputs=nature_data)
109
- block.load(get_submissions, inputs=gr.Variable("scifi"), outputs=scifi_data)
110
- block.load(get_submissions, inputs=gr.Variable("consentful"), outputs=consentful_data)
111
- block.load(get_submissions, inputs=gr.Variable("wildcard"), outputs=wildcard_data)
112
 
113
 
114
  block.launch()
 
5
  import pandas as pd
6
  from huggingface_hub import HfApi, repocard
7
 
8
+ def make_clickable_space(name, repo_type):
9
+ if repo_type == "spaces":
10
+ link = "https://huggingface.co/" + "spaces/" + name
11
+ elif repo_type == "models":
12
+ link = "https://huggingface.co/" + name
13
+ else:
14
+ link = "https://huggingface.co/" + "datasets/" + name
15
+ return f'<a target="_blank" href="{link}">{name.split("/")[-1]}</a>'
16
+
17
+ def get_repo_ids(repo_type):
 
 
18
  api = HfApi()
19
+ if repo_type == "spaces":
20
+ repos = api.list_spaces(filter=["hackathon-somos-nlp-2023"])
21
+ elif repo_type == "models":
22
+ repos = api.list_models(filter=["hackathon-somos-nlp-2023"])
23
+ else:
24
+ repos = api.list_datasets(filter=["hackathon-somos-nlp-2023"])
25
+ return repos
26
+
27
+ def get_submissions(repo_type):
28
+ submissions = get_repo_ids(repo_type)
29
+ leaderboard = []
 
 
30
 
31
  for submission in submissions:
32
+ leaderboard.append(
33
+ (
34
+ make_clickable_model(submission.id),
35
+ submission.likes,
 
 
 
 
 
36
  )
37
+ )
38
 
39
+ df = pd.DataFrame(data=leaderboard, columns=[Repo", "Likes"])
40
  df.sort_values(by=["Likes"], ascending=False, inplace=True)
41
  df.insert(0, "Rank", list(range(1, len(df) + 1)))
42
  return df
 
45
 
46
  with block:
47
  gr.Markdown(
48
+ """# Hackathon Somos NLP 2023 Leaderboard
 
 
 
 
 
49
  """
50
  )
51
  with gr.Tabs():
52
+ with gr.TabItem("Spaces (ML apps) 🐨 🌳 "):
53
  with gr.Row():
54
+ models_data = gr.components.Dataframe(
55
+ type="pandas", datatype=["number", "markdown", "number"]
56
  )
57
  with gr.Row():
58
  data_run = gr.Button("Refresh")
59
  data_run.click(
60
+ get_submissions, inputs=gr.Variable("spaces"), outputs=nature_data
61
  )
62
+ with gr.TabItem("Models"):
63
  with gr.Row():
64
  scifi_data = gr.components.Dataframe(
65
+ type="pandas", datatype=["number", "markdown", "number"]
66
  )
67
  with gr.Row():
68
  data_run = gr.Button("Refresh")
69
  data_run.click(
70
+ get_submissions, inputs=gr.Variable("models"), outputs=scifi_data
71
  )
72
+ with gr.TabItem("Datasets"):
73
  with gr.Row():
74
  consentful_data = gr.components.Dataframe(
75
+ type="pandas", datatype=["number", "markdown", "number"]
76
  )
77
  with gr.Row():
78
  data_run = gr.Button("Refresh")
79
  data_run.click(
80
+ get_submissions, inputs=gr.Variable("datasets"), outputs=consentful_data
 
 
 
 
 
 
 
 
 
 
 
 
81
  )
82
 
83
+
84
+ block.load(get_submissions, inputs=gr.Variable("spaces"), outputs=spaces_data)
85
+ block.load(get_submissions, inputs=gr.Variable("models"), outputs=models_data)
86
+ block.load(get_submissions, inputs=gr.Variable("datasets"), outputs=datasets_data)
87
 
88
 
89
  block.launch()