merve HF Staff commited on
Commit
4ec4c33
Β·
1 Parent(s): a56fee1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -0
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ __all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']
3
+
4
+ import gradio as gr
5
+ import pandas as pd
6
+ from huggingface_hub import list_models
7
+
8
+ def make_clickable_model(model_name, link=None):
9
+ if link is None:
10
+ link = "https://huggingface.co/" + model_name
11
+ # Remove user from model name
12
+ return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
13
+
14
+
15
+ def make_clickable_user(user_id):
16
+ link = "https://huggingface.co/" + user_id
17
+ return f'<a target="_blank" href="{link}">{user_id}</a>'
18
+
19
+ def get_submissions(category):
20
+ submissions = list_models(filter=["keras-dreambooth", category], full=True)
21
+ leaderboard_models = []
22
+
23
+ for submission in submissions:
24
+ # user, model, likes
25
+ user_id = submission.id.split("/")[0]
26
+ leaderboard_models.append(
27
+ (
28
+ make_clickable_user(user_id),
29
+ make_clickable_model(submission.id),
30
+ submission.likes,
31
+ )
32
+ )
33
+
34
+ df = pd.DataFrame(data=leaderboard_models, columns=["User", "Model", "Likes"])
35
+ df.sort_values(by=["Likes"], ascending=False, inplace=True)
36
+ df.insert(0, "Rank", list(range(1, len(df) + 1)))
37
+ return df
38
+
39
+ block = gr.Blocks()
40
+
41
+ with block:
42
+ gr.Markdown(
43
+ """# Keras DreamBooth Leaderboard
44
+
45
+ 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 (e.g. your pet or favourite dish) into the output domain of the model such that it can be synthesized with a _unique identifier_ in the prompt.
46
+
47
+ 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!
48
+
49
+ """
50
+ )
51
+ with gr.Tabs():
52
+ with gr.TabItem("Nature 🐨 🌳 "):
53
+ with gr.Row():
54
+ animal_data = gr.components.Dataframe(
55
+ type="pandas", datatype=["number", "markdown", "markdown", "number"]
56
+ )
57
+ with gr.Row():
58
+ data_run = gr.Button("Refresh")
59
+ data_run.click(
60
+ get_submissions, inputs=gr.Variable("nature"), outputs=nature_data
61
+ )
62
+ with gr.TabItem("Science Fiction & Fantasy πŸ§™β€β™€οΈ πŸ§›β€β™€οΈ πŸ€– "):
63
+ with gr.Row():
64
+ science_data = gr.components.Dataframe(
65
+ type="pandas", datatype=["number", "markdown", "markdown", "number"]
66
+ )
67
+ with gr.Row():
68
+ data_run = gr.Button("Refresh")
69
+ data_run.click(
70
+ get_submissions, inputs=gr.Variable("scifi"), outputs=scifi_data
71
+ )
72
+ with gr.TabItem("Consentful πŸ–ΌοΈ 🎨 "):
73
+ with gr.Row():
74
+ food_data = gr.components.Dataframe(
75
+ type="pandas", datatype=["number", "markdown", "markdown", "number"]
76
+ )
77
+ with gr.Row():
78
+ data_run = gr.Button("Refresh")
79
+ data_run.click(
80
+ get_submissions, inputs=gr.Variable("consentful"), outputs=consentful_data
81
+ )
82
+ with gr.TabItem("Wild Card πŸƒ"):
83
+ with gr.Row():
84
+ wildcard_data = gr.components.Dataframe(
85
+ type="pandas", datatype=["number", "markdown", "markdown", "number"]
86
+ )
87
+ with gr.Row():
88
+ data_run = gr.Button("Refresh")
89
+ data_run.click(
90
+ get_submissions,
91
+ inputs=gr.Variable("wildcard"),
92
+ outputs=wildcard_data,
93
+ )
94
+
95
+ block.load(get_submissions, inputs=gr.Variable("nature"), outputs=nature_data)
96
+ block.load(get_submissions, inputs=gr.Variable("scifi"), outputs=scifi_data)
97
+ block.load(get_submissions, inputs=gr.Variable("consentful"), outputs=consentful_data)
98
+ block.load(get_submissions, inputs=gr.Variable("wildcard"), outputs=wildcard_data)
99
+
100
+
101
+ block.launch()