update
Browse files8 unmodified lines910111213148 unmodified linespinned: falsedisable_embedding: truehf_oauth: true---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference8 unmodified lines91011121314151617188 unmodified linespinned: falsedisable_embedding: truehf_oauth: truehf_oauth_scopes:- "openid" # Always included: ID token- "profile" # Always included: user profile info- "write-repos" # Needed to create/upload to Spaces on behalf of the user---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
21 unmodified lines2223242526271129 unmodified lines115711581159116011611162116311641165116611671168116939 unmodified lines120912101211121212131214121523 unmodified lines1239124012411242124312444 unmodified lines1249125012511252125312541255125623 unmodified lines1280128112821283128412851286128712881289129021 unmodified linesimport gradio as grfrom huggingface_hub import InferenceClientfrom tavily import TavilyClient# Gradio supported languages for syntax highlightingGRADIO_SUPPORTED_LANGUAGES = [1129 unmodified lineslast_login_state = gr.State(None)with gr.Sidebar():# Remove Hugging Face Login Button and login-required message# login_button = gr.LoginButton(# value="Sign in with Hugging Face",# variant="huggingface",# size="lg"# )# login_required_msg = gr.Markdown("**Please sign in with Hugging Face to use the app.**", visible=True)input = gr.Textbox(label="What would you like to build?",placeholder="Describe your application...",39 unmodified lineslabel="Model",visible=True # Always visible)# Remove provider_choices and provider_dropdown, set provider_state to 'auto' onlyprovider_state = gr.State("auto")gr.Markdown("**Quick start**", visible=True)with gr.Column(visible=True) as quick_examples_col:23 unmodified linesoutputs=[current_model, image_input])# Remove the Advanced accordion and system prompt editing UIwith gr.Column():with gr.Tabs():4 unmodified linesinteractive=False,label="Generated code")# Rename button to 'π Deploy App'deploy_btn = gr.Button("π Deploy App", variant="primary", size="sm", visible=True)with gr.Tab("Preview"):sandbox = gr.HTML(label="Live preview")with gr.Tab("History"):23 unmodified lines# Deploy to Spaces logicdeploy_btn.click(fn=lambda code: deploy_to_spaces_static(code),inputs=code_output,outputs=None)if __name__ == "__main__":demo.queue(api_open=False, default_concurrency_limit=20).launch(ssr_mode=True, mcp_server=False, show_api=False)21 unmodified lines22232425262728291129 unmodified lines11591160116111621163116411651166116711681169117011711172117339 unmodified lines12131214121512161217121823 unmodified lines124212431244124512461247124812494 unmodified lines12541255125612571258125923 unmodified lines1283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133821 unmodified linesimport gradio as grfrom huggingface_hub import InferenceClientfrom tavily import TavilyClientfrom huggingface_hub import HfApiimport tempfile# Gradio supported languages for syntax highlightingGRADIO_SUPPORTED_LANGUAGES = [1129 unmodified lineslast_login_state = gr.State(None)with gr.Sidebar():login_button = gr.LoginButton()space_name_input = gr.Textbox(label="Space name (e.g. my-cool-space)",placeholder="Enter your Space name",lines=1,visible=True)deploy_btn = gr.Button("π Deploy App", variant="primary")deploy_status = gr.Markdown(visible=False, label="Deploy status")input = gr.Textbox(label="What would you like to build?",placeholder="Describe your application...",39 unmodified lineslabel="Model",visible=True # Always visible)provider_state = gr.State("auto")gr.Markdown("**Quick start**", visible=True)with gr.Column(visible=True) as quick_examples_col:23 unmodified linesoutputs=[current_model, image_input])# Remove the Advanced accordion and system prompt editing UI# login_button.render()# space_name_input.render()with gr.Column():with gr.Tabs():4 unmodified linesinteractive=False,label="Generated code")with gr.Tab("Preview"):sandbox = gr.HTML(label="Live preview")with gr.Tab("History"):23 unmodified lines# Deploy to Spaces logicdef deploy_to_user_space(code,space_name,profile: gr.OAuthProfile | None = None,token: gr.OAuthToken | None = None):if not code or not code.strip():return gr.update(value="No code to deploy.", visible=True)if profile is None or token is None:# Fallback to old method if not logged inreturn gr.update(value="Please log in with your Hugging Face account to deploy to your own Space. Otherwise, use the default deploy (opens in new tab).", visible=True)username = profile.usernamerepo_id = f"{username}/{space_name.strip()}"api = HfApi(token=token.token)# Create the Space if it doesn't existtry:# Fix create_repo call: use repo_id, not nameapi.create_repo(repo_id=repo_id, # e.g. username/space_namerepo_type="space",space_sdk="static", # or "gradio" if you want a Gradio Spaceexist_ok=True # Don't error if it already exists)except Exception as e:return gr.update(value=f"Error creating Space: {e}", visible=True)# Save code to a temporary filewith tempfile.NamedTemporaryFile("w", suffix=".html", delete=False) as f:f.write(code)temp_path = f.name# Upload the filetry:api.upload_file(path_or_fileobj=temp_path,path_in_repo="index.html",repo_id=repo_id,repo_type="space")space_url = f"https://huggingface.co/spaces/{repo_id}"return gr.update(value=f"β Deployed! [Open your Space here]({space_url})", visible=True)except Exception as e:return gr.update(value=f"Error uploading file: {e}", visible=True)# Connect the deploy button to the new functiondeploy_btn.click(deploy_to_user_space,inputs=[code_output, space_name_input],outputs=deploy_status)# Keep the old deploy method as fallback (if not logged in, user can still use the old method)# Optionally, you can keep the old deploy_btn.click for the default method as a secondary button.if __name__ == "__main__":demo.queue(api_open=False, default_concurrency_limit=20).launch(ssr_mode=True, mcp_server=False, show_api=False)
README.md+4
app.py+61-13