hide sdk from user
Browse files7759 unmodified lines7760776177627763776477657766210 unmodified lines7977797879797980798179827983798479857986798779887989799079917992799379947995799679977998220 unmodified lines821982208221822282238224822582268227822886 unmodified lines831583168317831883198320832117 unmodified lines833983408341834283438344834528 unmodified lines837483758376837783788379838053 unmodified lines843484358436843784388439844030 unmodified lines84718472847384748475847684778478847984808481848284838484848584868487848884898490517 unmodified lines90089009901090119012901390147759 unmodified lineschoices=[x[0] for x in sdk_choices],value="Static (HTML)",label="App SDK",visible=True)deploy_btn = gr.Button("π Deploy App", variant="primary", visible=True)deploy_status = gr.Markdown(visible=False, label="Deploy status")210 unmodified linesdef 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 switchingdef toggle_editors(language, code_text):220 unmodified linesdef show_deploy_components(*args):return [gr.Textbox(visible=True), gr.Dropdown(visible=True), gr.Button(visible=True)]def hide_deploy_components(*args):return [gr.Textbox(visible=True), gr.Dropdown(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]).then(preserve_space_info_for_followup,inputs=[history],17 unmodified lines).then(show_deploy_components,None,[space_name_input, sdk_dropdown, deploy_btn]).then(preserve_space_info_for_followup,inputs=[history],28 unmodified lines# Update deploy button text when space name changesspace_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])# Reset space name and button text when clearingclear_btn.click(lambda: [gr.update(value=""), gr.update(value="π Deploy App")],53 unmodified linesdef deploy_to_user_space(code,space_name,sdk_name, # new argumentprofile: gr.OAuthProfile | None = None,token: gr.OAuthToken | None = None):30 unmodified lines# This is a new space, create repo_id with current userusername = profile.usernamerepo_id = f"{username}/{space_name.strip()}"# Map SDK name to HF SDK slugsdk_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}sdk = sdk_map.get(sdk_name, "gradio")# Create API client with user's token for proper authenticationapi = HfApi(token=token.token)# Only create the repo for new spaces (not updates) and non-Transformers.js, non-Streamlit, and non-Svelte SDKsif not is_update and sdk != "docker" and sdk_name not in ["Transformers.js", "Svelte"]:try:api.create_repo(repo_id=repo_id, # e.g. username/space_name517 unmodified linesqueue=False,).then(deploy_to_user_space,inputs=[code_output, space_name_input, sdk_dropdown],outputs=deploy_status)# Keep the old deploy method as fallback (if not logged in, user can still use the old method)7759 unmodified lines7760776177627763776477657766210 unmodified lines79777978797979807981798279837984220 unmodified lines820582068207820882098210821182128213821486 unmodified lines830183028303830483058306830717 unmodified lines832583268327832883298330833128 unmodified lines836083618362836383648365836653 unmodified lines842084218422842384248425842630 unmodified lines84578458845984608461846284638464846584668467846884698470847184728473847484758476517 unmodified lines89948995899689978998899990007759 unmodified lineschoices=[x[0] for x in sdk_choices],value="Static (HTML)",label="App SDK",visible=False)deploy_btn = gr.Button("π Deploy App", variant="primary", visible=True)deploy_status = gr.Markdown(visible=False, label="Deploy status")210 unmodified linesdef update_code_language(language):return gr.update(language=get_gradio_language(language))language_dropdown.change(update_code_language, inputs=language_dropdown, outputs=code_output)# Toggle single vs multi-file editors for transformers.js and populate when switchingdef toggle_editors(language, code_text):220 unmodified linesdef show_deploy_components(*args):return [gr.Textbox(visible=True), gr.Button(visible=True)]def hide_deploy_components(*args):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, deploy_btn]).then(preserve_space_info_for_followup,inputs=[history],17 unmodified lines).then(show_deploy_components,None,[space_name_input, deploy_btn]).then(preserve_space_info_for_followup,inputs=[history],28 unmodified lines# Update deploy button text when space name changesspace_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, deploy_btn])# Reset space name and button text when clearingclear_btn.click(lambda: [gr.update(value=""), gr.update(value="π Deploy App")],53 unmodified linesdef deploy_to_user_space(code,space_name,language, # changed from sdk_name to languageprofile: gr.OAuthProfile | None = None,token: gr.OAuthToken | None = None):30 unmodified lines# This is a new space, create repo_id with current userusername = profile.usernamerepo_id = f"{username}/{space_name.strip()}"# Map language to HF SDK sluglanguage_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 = language_to_sdk_map.get(language, "gradio")# Create API client with user's token for proper authenticationapi = HfApi(token=token.token)# Only create the repo for new spaces (not updates) and non-Transformers.js, non-Streamlit, and non-Svelte SDKsif 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 linesqueue=False,).then(deploy_to_user_space,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