hide sdk from user
Browse files7759 unmodified lines77607761776277637763776477657766210 unmodified lines7977797879797980798179827983798479857986798779887989799079917992798079817995798279837984220 unmodified lines82058206820782228208820982108225821182128213821486 unmodified lines8301830283038318830483058306830717 unmodified lines8325832683278342832883298330833128 unmodified lines8360836183628377836383648365836653 unmodified lines8420842184228437842384248425842630 unmodified lines84578458845984748475847684778478847984808460846184628463846484658466846784828468846984708471847284878473847484758476517 unmodified lines899489958996901189978998899990007759 unmodified lines choices=[x[0] for x in sdk_choices], value="Static (HTML)", label="App SDK", visible=True visible=False ) deploy_btn = gr.Button("๐ Deploy App", variant="primary", visible=True) deploy_status = gr.Markdown(visible=False, label="Deploy status")210 unmodified lines def update_code_language(language): return gr.update(language=get_gradio_language(language))
def update_sdk_based_on_language(language): if language == "transformers.js": return gr.update(value="Transformers.js") elif language == "svelte": return gr.update(value="Svelte") elif language == "html": return gr.update(value="Static (HTML)") elif language == "streamlit": return gr.update(value="Streamlit (Python)") elif language == "gradio": return gr.update(value="Gradio (Python)") else: return gr.update(value="Gradio (Python)")
language_dropdown.change(update_code_language, inputs=language_dropdown, outputs=code_output) language_dropdown.change(update_sdk_based_on_language, inputs=language_dropdown, outputs=sdk_dropdown)
# Toggle single vs multi-file editors for transformers.js and populate when switching def toggle_editors(language, code_text):220 unmodified lines
def show_deploy_components(*args): return [gr.Textbox(visible=True), gr.Dropdown(visible=True), gr.Button(visible=True)] return [gr.Textbox(visible=True), gr.Button(visible=True)]
def hide_deploy_components(*args): return [gr.Textbox(visible=True), gr.Dropdown(visible=True), gr.Button(visible=True)] return [gr.Textbox(visible=True), gr.Button(visible=True)] def update_deploy_button_text(space_name): """Update deploy button text based on whether it's a new space or update"""86 unmodified lines ).then( show_deploy_components, None, [space_name_input, sdk_dropdown, deploy_btn] [space_name_input, deploy_btn] ).then( preserve_space_info_for_followup, inputs=[history],17 unmodified lines ).then( show_deploy_components, None, [space_name_input, sdk_dropdown, deploy_btn] [space_name_input, deploy_btn] ).then( preserve_space_info_for_followup, inputs=[history],28 unmodified lines # Update deploy button text when space name changes space_name_input.change(update_deploy_button_text, inputs=[space_name_input], outputs=[deploy_btn]) clear_btn.click(clear_history, outputs=[history, history_output, website_url_input]) clear_btn.click(hide_deploy_components, None, [space_name_input, sdk_dropdown, deploy_btn]) clear_btn.click(hide_deploy_components, None, [space_name_input, deploy_btn]) # Reset space name and button text when clearing clear_btn.click( lambda: [gr.update(value=""), gr.update(value="๐ Deploy App")],53 unmodified lines def deploy_to_user_space( code, space_name, sdk_name, # new argument language, # changed from sdk_name to language profile: gr.OAuthProfile | None = None, token: gr.OAuthToken | None = None ):30 unmodified lines # This is a new space, create repo_id with current user username = profile.username repo_id = f"{username}/{space_name.strip()}" # Map SDK name to HF SDK slug sdk_map = { "Gradio (Python)": "gradio", "Streamlit (Python)": "docker", # Use 'docker' for Streamlit Spaces "Static (HTML)": "static", "Transformers.js": "static", # Transformers.js uses static SDK "Svelte": "static" # Svelte uses static SDK # Map language to HF SDK slug language_to_sdk_map = { "gradio": "gradio", "streamlit": "docker", # Use 'docker' for Streamlit Spaces "html": "static", "transformers.js": "static", # Transformers.js uses static SDK "svelte": "static" # Svelte uses static SDK } sdk = sdk_map.get(sdk_name, "gradio") sdk = language_to_sdk_map.get(language, "gradio") # Create API client with user's token for proper authentication api = HfApi(token=token.token) # Only create the repo for new spaces (not updates) and non-Transformers.js, non-Streamlit, and non-Svelte SDKs if not is_update and sdk != "docker" and sdk_name not in ["Transformers.js", "Svelte"]: if not is_update and sdk != "docker" and language not in ["transformers.js", "svelte"]: try: api.create_repo( repo_id=repo_id, # e.g. username/space_name517 unmodified lines queue=False, ).then( deploy_to_user_space, inputs=[code_output, space_name_input, sdk_dropdown], inputs=[code_output, space_name_input, language_dropdown], outputs=deploy_status ) # Keep the old deploy method as fallback (if not logged in, user can still use the old method)app.py+17-31