anzorq commited on
Commit
5d2a090
β€’
1 Parent(s): 2f52940

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -48,14 +48,14 @@ def on_token_change(token):
48
  def on_load_model(user_model_id, other_model_id, token):
49
 
50
  if not user_model_id and not other_model_id:
51
- return None, None, None, None, gr.update(value=error_str("Please enter a model ID."))
52
 
53
  try:
54
  model_id = url_to_model_id(other_model_id) if other_model_id else user_model_id
55
  original_model_id = model_id
56
 
57
  if not has_diffusion_model(model_id, token):
58
- return None, None, None, None, gr.update(value=error_str("There are no diffusion weights in the model you selected."))
59
 
60
  user = whoami(token=token)
61
  model_id = user["name"] + "/" + model_id.split("/")[-1]
@@ -63,10 +63,10 @@ def on_load_model(user_model_id, other_model_id, token):
63
 
64
  description = f"""Demo for <a href="https://huggingface.co/{original_model_id}">{title}</a> Stable Diffusion model."""
65
 
66
- return gr.update(visible=True), gr.update(value=model_id), gr.update(value=title), gr.update(value=description), None
67
 
68
  except Exception as e:
69
- return None, None, None, None, gr.update(value=error_str(e))
70
 
71
  def add_space_badge_to_model_card(model_id, token):
72
 
@@ -94,7 +94,7 @@ def add_space_badge_to_model_card(model_id, token):
94
 
95
  os.remove(readme_file)
96
 
97
- def create_and_push(space_type, hardware, private_space, add_badge, other_model_name, radio_model_names, model_id, title, description, prefix, update, token):
98
 
99
  try:
100
 
@@ -151,7 +151,7 @@ def create_and_push(space_type, hardware, private_space, add_badge, other_model_
151
 
152
  # 6. Add the Space badge to the model card
153
  if add_badge:
154
- add_space_badge_to_model_card(model_id, token)
155
 
156
  return f"""
157
  Successfully created space at: <a href="{repo_url}" target="_blank">{repo_url}</a> <br>
@@ -200,6 +200,7 @@ with gr.Blocks() as demo:
200
  name = gr.Textbox(label="Name", placeholder="e.g. diffusers-demo")
201
  title = gr.Textbox(label="Title", placeholder="e.g. Diffusers Demo")
202
  description = gr.Textbox(label="Description", placeholder="e.g. Demo for my awesome Diffusers model", lines=5)
 
203
  prefix = gr.Textbox(label="Prefix tokens", placeholder="Tokens that are required to be present in the prompt, e.g. `rick and morty style`")
204
 
205
  gr.Markdown("""#### Choose space type
@@ -229,13 +230,13 @@ with gr.Blocks() as demo:
229
  btn_load.click(
230
  fn=on_load_model,
231
  inputs=[radio_model_names, other_model_name, input_token],
232
- outputs=[group_create, name, title, description, error_output],
233
  queue=False,
234
  scroll_to_output=True)
235
 
236
  btn_create.click(
237
  fn=create_and_push,
238
- inputs=[space_type, hardware, private_space, add_badge, other_model_name, radio_model_names, name, title, description, prefix, update, input_token],
239
  outputs=[error_output],
240
  scroll_to_output=True
241
  )
 
48
  def on_load_model(user_model_id, other_model_id, token):
49
 
50
  if not user_model_id and not other_model_id:
51
+ return None, None, None, None, gr.update(value=error_str("Please enter a model ID.")), None
52
 
53
  try:
54
  model_id = url_to_model_id(other_model_id) if other_model_id else user_model_id
55
  original_model_id = model_id
56
 
57
  if not has_diffusion_model(model_id, token):
58
+ return None, None, None, None, gr.update(value=error_str("There are no diffusion weights in the model you selected.")), None
59
 
60
  user = whoami(token=token)
61
  model_id = user["name"] + "/" + model_id.split("/")[-1]
 
63
 
64
  description = f"""Demo for <a href="https://huggingface.co/{original_model_id}">{title}</a> Stable Diffusion model."""
65
 
66
+ return gr.update(visible=True), gr.update(value=model_id), gr.update(value=title), gr.update(value=description), None, original_model_id
67
 
68
  except Exception as e:
69
+ return None, None, None, None, gr.update(value=error_str(e)), None
70
 
71
  def add_space_badge_to_model_card(model_id, token):
72
 
 
94
 
95
  os.remove(readme_file)
96
 
97
+ def create_and_push(space_type, hardware, private_space, add_badge, other_model_name, radio_model_names, model_id, title, description, prefix, update, token, original_model_id):
98
 
99
  try:
100
 
 
151
 
152
  # 6. Add the Space badge to the model card
153
  if add_badge:
154
+ add_space_badge_to_model_card(original_model_id, token)
155
 
156
  return f"""
157
  Successfully created space at: <a href="{repo_url}" target="_blank">{repo_url}</a> <br>
 
200
  name = gr.Textbox(label="Name", placeholder="e.g. diffusers-demo")
201
  title = gr.Textbox(label="Title", placeholder="e.g. Diffusers Demo")
202
  description = gr.Textbox(label="Description", placeholder="e.g. Demo for my awesome Diffusers model", lines=5)
203
+ original_model_id = gr.Textbox(visible=True)
204
  prefix = gr.Textbox(label="Prefix tokens", placeholder="Tokens that are required to be present in the prompt, e.g. `rick and morty style`")
205
 
206
  gr.Markdown("""#### Choose space type
 
230
  btn_load.click(
231
  fn=on_load_model,
232
  inputs=[radio_model_names, other_model_name, input_token],
233
+ outputs=[group_create, name, title, description, error_output, original_model_id],
234
  queue=False,
235
  scroll_to_output=True)
236
 
237
  btn_create.click(
238
  fn=create_and_push,
239
+ inputs=[space_type, hardware, private_space, add_badge, other_model_name, radio_model_names, name, title, description, prefix, update, input_token, original_model_id],
240
  outputs=[error_output],
241
  scroll_to_output=True
242
  )