akhaliq HF Staff commited on
Commit
2a96e6f
Β·
1 Parent(s): aadd58e

hide sdk from user

Browse files
Files changed (1) hide show
  1. app.py +17 -31
app.py CHANGED
@@ -7760,7 +7760,7 @@ with gr.Blocks(
7760
  choices=[x[0] for x in sdk_choices],
7761
  value="Static (HTML)",
7762
  label="App SDK",
7763
- visible=True
7764
  )
7765
  deploy_btn = gr.Button("πŸš€ Deploy App", variant="primary", visible=True)
7766
  deploy_status = gr.Markdown(visible=False, label="Deploy status")
@@ -7977,22 +7977,8 @@ with gr.Blocks(
7977
  def update_code_language(language):
7978
  return gr.update(language=get_gradio_language(language))
7979
 
7980
- def update_sdk_based_on_language(language):
7981
- if language == "transformers.js":
7982
- return gr.update(value="Transformers.js")
7983
- elif language == "svelte":
7984
- return gr.update(value="Svelte")
7985
- elif language == "html":
7986
- return gr.update(value="Static (HTML)")
7987
- elif language == "streamlit":
7988
- return gr.update(value="Streamlit (Python)")
7989
- elif language == "gradio":
7990
- return gr.update(value="Gradio (Python)")
7991
- else:
7992
- return gr.update(value="Gradio (Python)")
7993
 
7994
  language_dropdown.change(update_code_language, inputs=language_dropdown, outputs=code_output)
7995
- language_dropdown.change(update_sdk_based_on_language, inputs=language_dropdown, outputs=sdk_dropdown)
7996
 
7997
  # Toggle single vs multi-file editors for transformers.js and populate when switching
7998
  def toggle_editors(language, code_text):
@@ -8219,10 +8205,10 @@ with gr.Blocks(
8219
 
8220
 
8221
  def show_deploy_components(*args):
8222
- return [gr.Textbox(visible=True), gr.Dropdown(visible=True), gr.Button(visible=True)]
8223
 
8224
  def hide_deploy_components(*args):
8225
- return [gr.Textbox(visible=True), gr.Dropdown(visible=True), gr.Button(visible=True)]
8226
 
8227
  def update_deploy_button_text(space_name):
8228
  """Update deploy button text based on whether it's a new space or update"""
@@ -8315,7 +8301,7 @@ with gr.Blocks(
8315
  ).then(
8316
  show_deploy_components,
8317
  None,
8318
- [space_name_input, sdk_dropdown, deploy_btn]
8319
  ).then(
8320
  preserve_space_info_for_followup,
8321
  inputs=[history],
@@ -8339,7 +8325,7 @@ with gr.Blocks(
8339
  ).then(
8340
  show_deploy_components,
8341
  None,
8342
- [space_name_input, sdk_dropdown, deploy_btn]
8343
  ).then(
8344
  preserve_space_info_for_followup,
8345
  inputs=[history],
@@ -8374,7 +8360,7 @@ with gr.Blocks(
8374
  # Update deploy button text when space name changes
8375
  space_name_input.change(update_deploy_button_text, inputs=[space_name_input], outputs=[deploy_btn])
8376
  clear_btn.click(clear_history, outputs=[history, history_output, website_url_input])
8377
- clear_btn.click(hide_deploy_components, None, [space_name_input, sdk_dropdown, deploy_btn])
8378
  # Reset space name and button text when clearing
8379
  clear_btn.click(
8380
  lambda: [gr.update(value=""), gr.update(value="πŸš€ Deploy App")],
@@ -8434,7 +8420,7 @@ with gr.Blocks(
8434
  def deploy_to_user_space(
8435
  code,
8436
  space_name,
8437
- sdk_name, # new argument
8438
  profile: gr.OAuthProfile | None = None,
8439
  token: gr.OAuthToken | None = None
8440
  ):
@@ -8471,20 +8457,20 @@ with gr.Blocks(
8471
  # This is a new space, create repo_id with current user
8472
  username = profile.username
8473
  repo_id = f"{username}/{space_name.strip()}"
8474
- # Map SDK name to HF SDK slug
8475
- sdk_map = {
8476
- "Gradio (Python)": "gradio",
8477
- "Streamlit (Python)": "docker", # Use 'docker' for Streamlit Spaces
8478
- "Static (HTML)": "static",
8479
- "Transformers.js": "static", # Transformers.js uses static SDK
8480
- "Svelte": "static" # Svelte uses static SDK
8481
  }
8482
- sdk = sdk_map.get(sdk_name, "gradio")
8483
 
8484
  # Create API client with user's token for proper authentication
8485
  api = HfApi(token=token.token)
8486
  # Only create the repo for new spaces (not updates) and non-Transformers.js, non-Streamlit, and non-Svelte SDKs
8487
- if not is_update and sdk != "docker" and sdk_name not in ["Transformers.js", "Svelte"]:
8488
  try:
8489
  api.create_repo(
8490
  repo_id=repo_id, # e.g. username/space_name
@@ -9008,7 +8994,7 @@ with gr.Blocks(
9008
  queue=False,
9009
  ).then(
9010
  deploy_to_user_space,
9011
- inputs=[code_output, space_name_input, sdk_dropdown],
9012
  outputs=deploy_status
9013
  )
9014
  # Keep the old deploy method as fallback (if not logged in, user can still use the old method)
 
7760
  choices=[x[0] for x in sdk_choices],
7761
  value="Static (HTML)",
7762
  label="App SDK",
7763
+ visible=False
7764
  )
7765
  deploy_btn = gr.Button("πŸš€ Deploy App", variant="primary", visible=True)
7766
  deploy_status = gr.Markdown(visible=False, label="Deploy status")
 
7977
  def update_code_language(language):
7978
  return gr.update(language=get_gradio_language(language))
7979
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7980
 
7981
  language_dropdown.change(update_code_language, inputs=language_dropdown, outputs=code_output)
 
7982
 
7983
  # Toggle single vs multi-file editors for transformers.js and populate when switching
7984
  def toggle_editors(language, code_text):
 
8205
 
8206
 
8207
  def show_deploy_components(*args):
8208
+ return [gr.Textbox(visible=True), gr.Button(visible=True)]
8209
 
8210
  def hide_deploy_components(*args):
8211
+ return [gr.Textbox(visible=True), gr.Button(visible=True)]
8212
 
8213
  def update_deploy_button_text(space_name):
8214
  """Update deploy button text based on whether it's a new space or update"""
 
8301
  ).then(
8302
  show_deploy_components,
8303
  None,
8304
+ [space_name_input, deploy_btn]
8305
  ).then(
8306
  preserve_space_info_for_followup,
8307
  inputs=[history],
 
8325
  ).then(
8326
  show_deploy_components,
8327
  None,
8328
+ [space_name_input, deploy_btn]
8329
  ).then(
8330
  preserve_space_info_for_followup,
8331
  inputs=[history],
 
8360
  # Update deploy button text when space name changes
8361
  space_name_input.change(update_deploy_button_text, inputs=[space_name_input], outputs=[deploy_btn])
8362
  clear_btn.click(clear_history, outputs=[history, history_output, website_url_input])
8363
+ clear_btn.click(hide_deploy_components, None, [space_name_input, deploy_btn])
8364
  # Reset space name and button text when clearing
8365
  clear_btn.click(
8366
  lambda: [gr.update(value=""), gr.update(value="πŸš€ Deploy App")],
 
8420
  def deploy_to_user_space(
8421
  code,
8422
  space_name,
8423
+ language, # changed from sdk_name to language
8424
  profile: gr.OAuthProfile | None = None,
8425
  token: gr.OAuthToken | None = None
8426
  ):
 
8457
  # This is a new space, create repo_id with current user
8458
  username = profile.username
8459
  repo_id = f"{username}/{space_name.strip()}"
8460
+ # Map language to HF SDK slug
8461
+ language_to_sdk_map = {
8462
+ "gradio": "gradio",
8463
+ "streamlit": "docker", # Use 'docker' for Streamlit Spaces
8464
+ "html": "static",
8465
+ "transformers.js": "static", # Transformers.js uses static SDK
8466
+ "svelte": "static" # Svelte uses static SDK
8467
  }
8468
+ sdk = language_to_sdk_map.get(language, "gradio")
8469
 
8470
  # Create API client with user's token for proper authentication
8471
  api = HfApi(token=token.token)
8472
  # Only create the repo for new spaces (not updates) and non-Transformers.js, non-Streamlit, and non-Svelte SDKs
8473
+ if not is_update and sdk != "docker" and language not in ["transformers.js", "svelte"]:
8474
  try:
8475
  api.create_repo(
8476
  repo_id=repo_id, # e.g. username/space_name
 
8994
  queue=False,
8995
  ).then(
8996
  deploy_to_user_space,
8997
+ inputs=[code_output, space_name_input, language_dropdown],
8998
  outputs=deploy_status
8999
  )
9000
  # Keep the old deploy method as fallback (if not logged in, user can still use the old method)