ysharma HF staff commited on
Commit
6efb87d
β€’
1 Parent(s): 72a6c2f

created demo options

Browse files
Files changed (1) hide show
  1. app.py +43 -48
app.py CHANGED
@@ -10,47 +10,35 @@ from huggingface_hub import list_models
10
 
11
  from diffusers import StableDiffusionPipeline
12
 
13
- #submissions_list = list_models(filter=["dreambooth-hackathon", category], full=True)
14
- #spaces_pipeline_load = [submission.id for submission in submissions_list ]
15
- #for ids in spaces_pipeline_load:
16
- # mydict[ids] = StableDiffusionPipeline.from_pretrained(ids) #('ashiqabdulkhader/shiba-dog')
17
- #f"pipeline{ids.split('//')[-1]}" = StableDiffusionPipeline.from_pretrained(ids) #('ashiqabdulkhader/shiba-dog')
18
-
19
- #pipeline = StableDiffusionPipeline.from_pretrained("ashiqabdulkhader/shiba-dog") #('pharma/sugar-glider')
20
- #image = pipeline().images[0]
21
- #image
22
- #https://huggingface.co/ashiqabdulkhader/shiba-dog
23
- def filter_species(species):
24
- return gr.Dropdown.update(choices=species_map[species], value=species_map[species][1]), gr.update(visible=True)
25
-
26
- # %% app.ipynb 1
27
- def make_clickable_demo(model_name, prompt): #link=None):
28
- #if link is None:
29
- # link = "https://huggingface.co/" + model_name
30
- # Remove user from model name
31
- prompt = "a photo of " + ' '.join(model_name.split('/')[-1].split['-']) + str(prompt)
32
-
33
- return gr.Button.update()
34
-
35
- def make_clickable_model(model_name,prompt, link=None):
36
- if link is None:
37
- link = "https://huggingface.co/" + model_name
38
 
39
- #adding functionality for demo
40
- user_model_nm = model_name.split('/')[-1]
41
- print(f"user and model name is - {user_model_nm}")
42
  if '-' in user_model_nm:
43
- model_nm = " ".join(user_model_nm.split('-'))
44
  else:
45
- model_nm = user_model_nm
46
- print(f"model name is - {model_nm}")
47
- prompt = "a photo of " + model_nm + str(prompt)
 
 
48
  pipeline = StableDiffusionPipeline.from_pretrained(model_name) #("ashiqabdulkhader/shiba-dog") #('pharma/sugar-glider')
49
- image_demo = pipeline(prompt).images[0]
50
-
51
- # Remove user from model name
52
- return image_out.Update(value=image_demo, label=model_name.split("/")[-1]) #f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
53
 
 
 
 
 
 
 
54
  def make_clickable_user(user_id):
55
  link = "https://huggingface.co/" + user_id
56
  return f'<a target="_blank" href="{link}">{user_id}</a>'
@@ -63,15 +51,20 @@ def get_submissions(category, prompt):
63
  for submission in submissions:
64
  # user, model, likes
65
  user_id = submission.id.split("/")[0]
 
 
 
 
66
  leaderboard_models.append(
67
  (
68
  make_clickable_user(user_id),
69
  make_clickable_model(submission.id, prompt),
70
  submission.likes,
 
71
  )
72
  )
73
 
74
- df = pd.DataFrame(data=leaderboard_models, columns=["User", "Model", "Likes"])
75
  df.sort_values(by=["Likes"], ascending=False, inplace=True)
76
  df.insert(0, "Rank", list(range(1, len(df) + 1)))
77
  return df
@@ -92,12 +85,15 @@ with block:
92
  )
93
  with gr.Row():
94
  prompt_in = gr.Textbox(label="Type in a Prompt. This will be suffixed to 'a photo of <model name>', so prompt accordingly -", value="")
95
- #button_in = gr.Button(label = "Generate Image using this model")
 
 
 
96
  with gr.Tabs():
97
  with gr.TabItem("Animal 🐨"):
98
  with gr.Row():
99
  animal_data = gr.components.Dataframe(
100
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
101
  )
102
  with gr.Row():
103
  data_run = gr.Button("Refresh")
@@ -109,7 +105,7 @@ with block:
109
  with gr.TabItem("Science πŸ”¬"):
110
  with gr.Row():
111
  science_data = gr.components.Dataframe(
112
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
113
  )
114
  with gr.Row():
115
  data_run = gr.Button("Refresh")
@@ -119,7 +115,7 @@ with block:
119
  with gr.TabItem("Food πŸ”"):
120
  with gr.Row():
121
  food_data = gr.components.Dataframe(
122
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
123
  )
124
  with gr.Row():
125
  data_run = gr.Button("Refresh")
@@ -129,7 +125,7 @@ with block:
129
  with gr.TabItem("Landscape πŸ”"):
130
  with gr.Row():
131
  landscape_data = gr.components.Dataframe(
132
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
133
  )
134
  with gr.Row():
135
  data_run = gr.Button("Refresh")
@@ -141,7 +137,7 @@ with block:
141
  with gr.TabItem("Wilcard πŸ”₯"):
142
  with gr.Row():
143
  wildcard_data = gr.components.Dataframe(
144
- type="pandas", datatype=["number", "markdown", "markdown", "number"]
145
  )
146
  with gr.Row():
147
  data_run = gr.Button("Refresh")
@@ -151,11 +147,10 @@ with block:
151
  outputs=wildcard_data,
152
  )
153
 
154
- with gr.Row() : #as your_model_demo :
155
- image_out = gr.Image()
156
-
157
- #button_in.click(make_clickable_demo, prompt_in, your_model_demo)
158
-
159
  block.load(get_submissions, inputs=[gr.Variable("animal"), prompt_in], outputs=animal_data)
160
  block.load(get_submissions, inputs=[gr.Variable("science"), prompt_in], outputs=science_data)
161
  block.load(get_submissions, inputs=[gr.Variable("food"), prompt_in], outputs=food_data)
 
10
 
11
  from diffusers import StableDiffusionPipeline
12
 
13
+ # %% app.ipynb 1
14
+ def get_model_list(category):
15
+ submissions_list = list_models(filter=["dreambooth-hackathon", category], full=True)
16
+ spaces_pipeline_load = [submission.id for submission in submissions_list ]
17
+ return gr.Dropdown.update(choices=spaces_pipeline_load , value=spaces_pipeline_load[5])
18
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ def get_initial_prompt(model_nm):
21
+ #a photo of peterj/shbrcky-dog
22
+ user_model_nm = model_nm.split('/')[-1]
23
  if '-' in user_model_nm:
24
+ prompt = " ".join(user_model_nm.split('-'))
25
  else:
26
+ prompt = user_model_nm
27
+ return gr.Textbox.update(value="a photo of " + prompt + " ")
28
+
29
+ def make_demo(model_name, prompt): #link=None):
30
+ #prompt = "a photo of " + ' '.join(model_name.split('/')[-1].split['-']) + str(prompt)
31
  pipeline = StableDiffusionPipeline.from_pretrained(model_name) #("ashiqabdulkhader/shiba-dog") #('pharma/sugar-glider')
32
+ image_demo = pipeline(prompt).images[0]
33
+ return image_demo #gr.Button.update()
34
+
 
35
 
36
+ def make_clickable_model(model_name, link=None):
37
+ if link is None:
38
+ link = "https://huggingface.co/" + model_name
39
+ # Remove user from model name
40
+ return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
41
+
42
  def make_clickable_user(user_id):
43
  link = "https://huggingface.co/" + user_id
44
  return f'<a target="_blank" href="{link}">{user_id}</a>'
 
51
  for submission in submissions:
52
  # user, model, likes
53
  user_id = submission.id.split("/")[0]
54
+ model_nm = submission.id.split("/")[-1]
55
+ if '-' in model_nm:
56
+ model_nm = " ".join(model_nm.split('-'))
57
+ #button_html = get_button()
58
  leaderboard_models.append(
59
  (
60
  make_clickable_user(user_id),
61
  make_clickable_model(submission.id, prompt),
62
  submission.likes,
63
+ #button_html #'a photo of ' + model_nm + " "
64
  )
65
  )
66
 
67
+ df = pd.DataFrame(data=leaderboard_models, columns=["User", "Model", "Likes", ])
68
  df.sort_values(by=["Likes"], ascending=False, inplace=True)
69
  df.insert(0, "Rank", list(range(1, len(df) + 1)))
70
  return df
 
85
  )
86
  with gr.Row():
87
  prompt_in = gr.Textbox(label="Type in a Prompt. This will be suffixed to 'a photo of <model name>', so prompt accordingly -", value="")
88
+ with gr.Column():
89
+ gr.Dropdown(label="Choose a dreamboooth model", value)
90
+ button_in = gr.Button(label = "Generate Image using this model")
91
+ image_out = gr.Image()
92
  with gr.Tabs():
93
  with gr.TabItem("Animal 🐨"):
94
  with gr.Row():
95
  animal_data = gr.components.Dataframe(
96
+ type="pandas", datatype=["number", "markdown", "markdown", "number","str"], interactive = True
97
  )
98
  with gr.Row():
99
  data_run = gr.Button("Refresh")
 
105
  with gr.TabItem("Science πŸ”¬"):
106
  with gr.Row():
107
  science_data = gr.components.Dataframe(
108
+ type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True
109
  )
110
  with gr.Row():
111
  data_run = gr.Button("Refresh")
 
115
  with gr.TabItem("Food πŸ”"):
116
  with gr.Row():
117
  food_data = gr.components.Dataframe(
118
+ type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True
119
  )
120
  with gr.Row():
121
  data_run = gr.Button("Refresh")
 
125
  with gr.TabItem("Landscape πŸ”"):
126
  with gr.Row():
127
  landscape_data = gr.components.Dataframe(
128
+ type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True
129
  )
130
  with gr.Row():
131
  data_run = gr.Button("Refresh")
 
137
  with gr.TabItem("Wilcard πŸ”₯"):
138
  with gr.Row():
139
  wildcard_data = gr.components.Dataframe(
140
+ type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True
141
  )
142
  with gr.Row():
143
  data_run = gr.Button("Refresh")
 
147
  outputs=wildcard_data,
148
  )
149
 
150
+ theme.change(get_model_list, theme, model_list )
151
+ model_list.change(get_initial_prompt, model_list, prompt_in )
152
+ button_in.click(make_demo, [model_list, prompt_in], image_out)
153
+
 
154
  block.load(get_submissions, inputs=[gr.Variable("animal"), prompt_in], outputs=animal_data)
155
  block.load(get_submissions, inputs=[gr.Variable("science"), prompt_in], outputs=science_data)
156
  block.load(get_submissions, inputs=[gr.Variable("food"), prompt_in], outputs=food_data)