svjack commited on
Commit
2e86483
β€’
1 Parent(s): f642081

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -34
app.py CHANGED
@@ -23,8 +23,8 @@ MAX_MODEL_NUM = 300
23
  Yntec digplay
24
  '''
25
 
26
- hf_civital_image_info_dataset = load_dataset("svjack/hf_civital_image_info_v0", token = API_TOKEN)
27
- hf_civital_image_info_df = hf_civital_image_info_dataset["train"].to_pandas()
28
 
29
  def gen_interface(model_name, max_times = 3):
30
  times = 0
@@ -53,7 +53,7 @@ def jpg_val_to_img(jpg_bytes):
53
  return toImgPIL(img)
54
 
55
 
56
- model_list = hf_civital_image_info_df["hf_repo_id"].drop_duplicates().values.tolist()
57
  model_interface_list = []
58
  for model_name in tqdm(model_list):
59
  gr_model_interface = gen_interface(model_name)
@@ -63,7 +63,7 @@ for model_name in tqdm(model_list):
63
  break
64
  print("load model num : {}".format(len(model_interface_list)))
65
 
66
- def get_civital_iframe(url, width = 1400, height = 768, as_html = True, visible = False):
67
  html= '''
68
  <div style="justify-content: center; display: flex;">
69
  <iframe
@@ -79,23 +79,23 @@ def get_civital_iframe(url, width = 1400, height = 768, as_html = True, visible
79
  return html
80
 
81
  def get_info_by_interface(gr_interface, model_interface_list = model_interface_list):
82
- #### out: (gr_interface, civital_url, civital_info)
83
  if hasattr(gr_interface, "app"):
84
- civital_url = hf_civital_image_info_df[
85
- hf_civital_image_info_df["hf_repo_id"] == gr_interface.title
86
- ]["civital_url"].iloc[0]
87
- civital_info = hf_civital_image_info_df[
88
- hf_civital_image_info_df["hf_repo_id"] == gr_interface.title
89
  ][["prompt", "image"]].values.tolist()
90
- return gr_interface ,civital_url, civital_info
91
  else:
92
- civital_url = hf_civital_image_info_df[
93
- hf_civital_image_info_df["hf_repo_id"] == gr_interface
94
- ]["civital_url"].iloc[0]
95
- civital_info = hf_civital_image_info_df[
96
- hf_civital_image_info_df["hf_repo_id"] == gr_interface
97
  ][["prompt", "image"]].values.tolist()
98
- return list(filter(lambda x:x.title == gr_interface, model_interface_list))[0] ,civital_url, civital_info
99
 
100
  def read_image_from_url(url):
101
  response = requests.get(url)
@@ -131,9 +131,9 @@ def image_click(images, evt: gr.SelectData, gr_interface_value,
131
  return prompt
132
  #return prompt, im
133
 
134
- def try_repo_act_func(civital_url, show_civital_button):
135
- repo_html_iframe_hide = get_civital_iframe(civital_url, visible = True if show_civital_button == "Show Civital Page" else False)
136
- return repo_html_iframe_hide, gr.Button("Hide Civital Page" if show_civital_button == "Show Civital Page" else "Show Civital Page")
137
 
138
  with gr.Blocks(
139
  css = '''
@@ -152,7 +152,7 @@ with gr.Blocks(
152
  '''
153
  <center>
154
  <div class="header">
155
- <h1 class = "logo"> <img src="https://huggingface.co/spaces/svjack/Civital-Stable-Diffusion-HF/resolve/main/civital_logo.webp" alt="logo" /> πŸ€— Civital Model on Huggingface </h1>
156
  </center>
157
  '''
158
  )
@@ -165,26 +165,26 @@ with gr.Blocks(
165
  value=sorted(map(lambda x: x.title, model_interface_list))[0],)
166
  with gr.Column():
167
  with gr.Row():
168
- civital_prompt = gr.Textbox(label = "🀭 Civital Prompt (Click from πŸ‘‰ right gallery to get them, and You can edit ✍️ yourself) Don't use them to generate NSFW content, such as porns. πŸ˜¬πŸ‘Ž Or you will get βŒπŸ‘€",
169
  interactive = True,
170
  )
171
  gen_button = gr.Button(label = "Generate")
172
  hf_image = gr.Image(label = "🀭 Image generate by πŸ€— Huggingface", height = 768)
173
 
174
  with gr.Column():
175
- civital_info_gallery = gr.Gallery(
176
  pd.Series(
177
  get_info_by_interface(hf_model_dropdown.value)[2]
178
  ).sample(n = min(len(get_info_by_interface(hf_model_dropdown.value)[2]), 30)).map(lambda t2: t2[1]).map(lambda x: x["bytes"]).map(jpg_val_to_img).values.tolist(),
179
  height = 1024,
180
- label = "πŸ–±οΈπŸ‘‡ ➑️ πŸ‘ˆ Civital image samples",
181
  object_fit = "contain"
182
  )
183
 
184
  with gr.Row():
185
  with gr.Column():
186
- try_repo_button = gr.Button("Show Civital Page")
187
- civital_iframe_html = get_civital_iframe(
188
  get_info_by_interface(hf_model_dropdown.value)[1]
189
  )
190
 
@@ -193,22 +193,22 @@ with gr.Blocks(
193
  get_info_by_interface(x)[2]
194
  ).sample(n = min(len(get_info_by_interface(x)[2]), 30)).map(lambda t2: t2[1]).map(lambda x: x["bytes"]).map(jpg_val_to_img).values.tolist(),
195
  hf_model_dropdown,
196
- civital_info_gallery
197
  )
198
  hf_model_dropdown.change(
199
- lambda _: (gr.Button("Show Civital Page"), gr.HTML(visible = False)),
200
  None,
201
- [try_repo_button, civital_iframe_html]
202
  )
203
 
204
- civital_info_gallery.select(
205
  image_click,
206
- [civital_info_gallery, hf_model_dropdown],
207
- civital_prompt
208
  )
209
  gen_button.click(lambda hf_model_name, text_prompt:
210
  get_info_by_interface(hf_model_name)[0](text_prompt),
211
- [hf_model_dropdown, civital_prompt],
212
  hf_image
213
  )
214
 
@@ -217,7 +217,7 @@ with gr.Blocks(
217
  get_info_by_interface(hf_model_name)[1]
218
  , button),
219
  [hf_model_dropdown, try_repo_button],
220
- [civital_iframe_html, try_repo_button]
221
  )
222
 
223
  demo.launch(show_api = False)
 
23
  Yntec digplay
24
  '''
25
 
26
+ hf_civitai_image_info_dataset = load_dataset("svjack/hf_civitai_image_info_v0", token = API_TOKEN)
27
+ hf_civitai_image_info_df = hf_civitai_image_info_dataset["train"].to_pandas()
28
 
29
  def gen_interface(model_name, max_times = 3):
30
  times = 0
 
53
  return toImgPIL(img)
54
 
55
 
56
+ model_list = hf_civitai_image_info_df["hf_repo_id"].drop_duplicates().values.tolist()
57
  model_interface_list = []
58
  for model_name in tqdm(model_list):
59
  gr_model_interface = gen_interface(model_name)
 
63
  break
64
  print("load model num : {}".format(len(model_interface_list)))
65
 
66
+ def get_civitai_iframe(url, width = 1400, height = 768, as_html = True, visible = False):
67
  html= '''
68
  <div style="justify-content: center; display: flex;">
69
  <iframe
 
79
  return html
80
 
81
  def get_info_by_interface(gr_interface, model_interface_list = model_interface_list):
82
+ #### out: (gr_interface, civitai_url, civitai_info)
83
  if hasattr(gr_interface, "app"):
84
+ civitai_url = hf_civitai_image_info_df[
85
+ hf_civitai_image_info_df["hf_repo_id"] == gr_interface.title
86
+ ]["civitai_url"].iloc[0]
87
+ civitai_info = hf_civitai_image_info_df[
88
+ hf_civitai_image_info_df["hf_repo_id"] == gr_interface.title
89
  ][["prompt", "image"]].values.tolist()
90
+ return gr_interface ,civitai_url, civitai_info
91
  else:
92
+ civitai_url = hf_civitai_image_info_df[
93
+ hf_civitai_image_info_df["hf_repo_id"] == gr_interface
94
+ ]["civitai_url"].iloc[0]
95
+ civitai_info = hf_civitai_image_info_df[
96
+ hf_civitai_image_info_df["hf_repo_id"] == gr_interface
97
  ][["prompt", "image"]].values.tolist()
98
+ return list(filter(lambda x:x.title == gr_interface, model_interface_list))[0] ,civitai_url, civitai_info
99
 
100
  def read_image_from_url(url):
101
  response = requests.get(url)
 
131
  return prompt
132
  #return prompt, im
133
 
134
+ def try_repo_act_func(civitai_url, show_civitai_button):
135
+ repo_html_iframe_hide = get_civitai_iframe(civitai_url, visible = True if show_civitai_button == "Show Civitai Page" else False)
136
+ return repo_html_iframe_hide, gr.Button("Hide Civitai Page" if show_civitai_button == "Show Civitai Page" else "Show Civitai Page")
137
 
138
  with gr.Blocks(
139
  css = '''
 
152
  '''
153
  <center>
154
  <div class="header">
155
+ <h1 class = "logo"> <img src="https://huggingface.co/spaces/svjack/Civitai-Stable-Diffusion-HF/resolve/main/civitai_logo.webp" alt="logo" /> πŸ€— Civitai Model on Huggingface </h1>
156
  </center>
157
  '''
158
  )
 
165
  value=sorted(map(lambda x: x.title, model_interface_list))[0],)
166
  with gr.Column():
167
  with gr.Row():
168
+ civitai_prompt = gr.Textbox(label = "🀭 Civitai Prompt (Click from πŸ‘‰ right gallery to get them, and You can edit ✍️ yourself) Don't use them to generate NSFW content, such as porns. πŸ˜¬πŸ‘Ž Or you will get βŒπŸ‘€",
169
  interactive = True,
170
  )
171
  gen_button = gr.Button(label = "Generate")
172
  hf_image = gr.Image(label = "🀭 Image generate by πŸ€— Huggingface", height = 768)
173
 
174
  with gr.Column():
175
+ civitai_info_gallery = gr.Gallery(
176
  pd.Series(
177
  get_info_by_interface(hf_model_dropdown.value)[2]
178
  ).sample(n = min(len(get_info_by_interface(hf_model_dropdown.value)[2]), 30)).map(lambda t2: t2[1]).map(lambda x: x["bytes"]).map(jpg_val_to_img).values.tolist(),
179
  height = 1024,
180
+ label = "πŸ–±οΈπŸ‘‡ ➑️ πŸ‘ˆ Civitai image samples",
181
  object_fit = "contain"
182
  )
183
 
184
  with gr.Row():
185
  with gr.Column():
186
+ try_repo_button = gr.Button("Show Civitai Page")
187
+ civitai_iframe_html = get_civitai_iframe(
188
  get_info_by_interface(hf_model_dropdown.value)[1]
189
  )
190
 
 
193
  get_info_by_interface(x)[2]
194
  ).sample(n = min(len(get_info_by_interface(x)[2]), 30)).map(lambda t2: t2[1]).map(lambda x: x["bytes"]).map(jpg_val_to_img).values.tolist(),
195
  hf_model_dropdown,
196
+ civitai_info_gallery
197
  )
198
  hf_model_dropdown.change(
199
+ lambda _: (gr.Button("Show Civitai Page"), gr.HTML(visible = False)),
200
  None,
201
+ [try_repo_button, civitai_iframe_html]
202
  )
203
 
204
+ civitai_info_gallery.select(
205
  image_click,
206
+ [civitai_info_gallery, hf_model_dropdown],
207
+ civitai_prompt
208
  )
209
  gen_button.click(lambda hf_model_name, text_prompt:
210
  get_info_by_interface(hf_model_name)[0](text_prompt),
211
+ [hf_model_dropdown, civitai_prompt],
212
  hf_image
213
  )
214
 
 
217
  get_info_by_interface(hf_model_name)[1]
218
  , button),
219
  [hf_model_dropdown, try_repo_button],
220
+ [civitai_iframe_html, try_repo_button]
221
  )
222
 
223
  demo.launch(show_api = False)