Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -579,20 +579,16 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
|
|
579 |
login_btn = gr.LoginButton(variant="huggingface")
|
580 |
|
581 |
# Initial load to check login status
|
582 |
-
# Removed _preprocess=False
|
583 |
ai_builder_tab.load(show_profile, outputs=login_status)
|
584 |
# Update status on login click
|
585 |
-
# Removed _preprocess=False
|
586 |
login_btn.click(show_profile, outputs=login_status)
|
587 |
# Store profile and token in state on login click
|
588 |
-
# Removed _preprocess=False
|
589 |
login_btn.click(lambda x: x, inputs=[login_btn], outputs=[hf_profile, hf_token])
|
590 |
|
591 |
gr.Markdown("## Google AI Studio API Key")
|
592 |
gemini_input = gr.Textbox(label="API Key", type="password", interactive=True)
|
593 |
gemini_status = gr.Markdown("")
|
594 |
|
595 |
-
# Removed _preprocess=False
|
596 |
gemini_input.change(lambda k: k, inputs=gemini_input, outputs=gemini_key)
|
597 |
|
598 |
gr.Markdown("## Gemini Model")
|
@@ -606,24 +602,21 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
|
|
606 |
label="Select model",
|
607 |
interactive=True
|
608 |
)
|
609 |
-
# Removed _preprocess=False
|
610 |
model_selector.change(lambda m: m, inputs=model_selector, outputs=gemini_model)
|
611 |
|
612 |
# Configure Gemini status on load and when key/model changes
|
613 |
-
# Removed _preprocess=False from load
|
614 |
ai_builder_tab.load(
|
615 |
configure_gemini,
|
616 |
inputs=[gemini_key, gemini_model],
|
617 |
outputs=[gemini_status]
|
618 |
)
|
619 |
-
#
|
620 |
-
|
621 |
configure_gemini,
|
622 |
inputs=[gemini_key, gemini_model],
|
623 |
outputs=[gemini_status]
|
624 |
)
|
625 |
-
|
626 |
-
model_selector.change(
|
627 |
configure_gemini,
|
628 |
inputs=[gemini_key, gemini_model],
|
629 |
outputs=[gemini_status]
|
@@ -632,7 +625,6 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
|
|
632 |
|
633 |
gr.Markdown("## Space SDK")
|
634 |
sdk_selector = gr.Radio(choices=["gradio","streamlit"], value="gradio", label="Template SDK", interactive=True)
|
635 |
-
# Removed _preprocess=False
|
636 |
sdk_selector.change(lambda s: s, inputs=sdk_selector, outputs=sdk_state)
|
637 |
|
638 |
gr.Markdown("## Workflow Status")
|
@@ -651,37 +643,42 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
|
|
651 |
is_gemini_ready = key is not None and model is not None
|
652 |
return gr.update(interactive=is_logged_in and is_gemini_ready)
|
653 |
|
654 |
-
#
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
|
|
659 |
)
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
outputs=[send_btn]
|
665 |
)
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
|
|
|
|
|
|
|
|
671 |
)
|
672 |
-
|
673 |
-
|
|
|
674 |
update_send_button_state,
|
675 |
inputs=[hf_profile, hf_token, gemini_key, gemini_model],
|
676 |
outputs=[send_btn]
|
677 |
)
|
678 |
|
|
|
679 |
iframe = gr.HTML("<p>No Space created yet.</p>")
|
680 |
build_txt = gr.Textbox(label="Build Logs", lines=10, interactive=False, value="")
|
681 |
run_txt = gr.Textbox(label="Container Logs", lines=10, interactive=False, value="")
|
682 |
|
683 |
# The main event handler for the Send button
|
684 |
-
# Removed _preprocess=False (it wasn't on this one anyway)
|
685 |
send_btn.click(
|
686 |
ai_workflow_chat,
|
687 |
inputs=[
|
@@ -705,9 +702,7 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
|
|
705 |
)
|
706 |
|
707 |
# Link state variables to UI status displays (reactive updates)
|
708 |
-
# Removed _preprocess=False
|
709 |
workflow.change(lambda s: s, inputs=workflow, outputs=status_text)
|
710 |
-
# Removed _preprocess=False
|
711 |
repo_id.change(lambda r: r if r else "None", inputs=repo_id, outputs=repo_id_text)
|
712 |
|
713 |
|
|
|
579 |
login_btn = gr.LoginButton(variant="huggingface")
|
580 |
|
581 |
# Initial load to check login status
|
|
|
582 |
ai_builder_tab.load(show_profile, outputs=login_status)
|
583 |
# Update status on login click
|
|
|
584 |
login_btn.click(show_profile, outputs=login_status)
|
585 |
# Store profile and token in state on login click
|
|
|
586 |
login_btn.click(lambda x: x, inputs=[login_btn], outputs=[hf_profile, hf_token])
|
587 |
|
588 |
gr.Markdown("## Google AI Studio API Key")
|
589 |
gemini_input = gr.Textbox(label="API Key", type="password", interactive=True)
|
590 |
gemini_status = gr.Markdown("")
|
591 |
|
|
|
592 |
gemini_input.change(lambda k: k, inputs=gemini_input, outputs=gemini_key)
|
593 |
|
594 |
gr.Markdown("## Gemini Model")
|
|
|
602 |
label="Select model",
|
603 |
interactive=True
|
604 |
)
|
|
|
605 |
model_selector.change(lambda m: m, inputs=model_selector, outputs=gemini_model)
|
606 |
|
607 |
# Configure Gemini status on load and when key/model changes
|
|
|
608 |
ai_builder_tab.load(
|
609 |
configure_gemini,
|
610 |
inputs=[gemini_key, gemini_model],
|
611 |
outputs=[gemini_status]
|
612 |
)
|
613 |
+
# These should trigger configure_gemini whenever the relevant state changes
|
614 |
+
gemini_key.change(
|
615 |
configure_gemini,
|
616 |
inputs=[gemini_key, gemini_model],
|
617 |
outputs=[gemini_status]
|
618 |
)
|
619 |
+
gemini_model.change(
|
|
|
620 |
configure_gemini,
|
621 |
inputs=[gemini_key, gemini_model],
|
622 |
outputs=[gemini_status]
|
|
|
625 |
|
626 |
gr.Markdown("## Space SDK")
|
627 |
sdk_selector = gr.Radio(choices=["gradio","streamlit"], value="gradio", label="Template SDK", interactive=True)
|
|
|
628 |
sdk_selector.change(lambda s: s, inputs=sdk_selector, outputs=sdk_state)
|
629 |
|
630 |
gr.Markdown("## Workflow Status")
|
|
|
643 |
is_gemini_ready = key is not None and model is not None
|
644 |
return gr.update(interactive=is_logged_in and is_gemini_ready)
|
645 |
|
646 |
+
# Bind update_send_button_state to the *change* of the relevant state variables
|
647 |
+
# This ensures it's called with the correct 4 state values whenever any of them change.
|
648 |
+
hf_profile.change(
|
649 |
+
update_send_button_state,
|
650 |
+
inputs=[hf_profile, hf_token, gemini_key, gemini_model],
|
651 |
+
outputs=[send_btn]
|
652 |
)
|
653 |
+
hf_token.change(
|
654 |
+
update_send_button_state,
|
655 |
+
inputs=[hf_profile, hf_token, gemini_key, gemini_model],
|
656 |
+
outputs=[send_btn]
|
|
|
657 |
)
|
658 |
+
gemini_key.change(
|
659 |
+
update_send_button_state,
|
660 |
+
inputs=[hf_profile, hf_token, gemini_key, gemini_model],
|
661 |
+
outputs=[send_btn]
|
662 |
+
)
|
663 |
+
gemini_model.change(
|
664 |
+
update_send_button_state,
|
665 |
+
inputs=[hf_profile, hf_token, gemini_key, gemini_model],
|
666 |
+
outputs=[send_btn]
|
667 |
)
|
668 |
+
|
669 |
+
# Keep the initial load trigger as well
|
670 |
+
ai_builder_tab.load(
|
671 |
update_send_button_state,
|
672 |
inputs=[hf_profile, hf_token, gemini_key, gemini_model],
|
673 |
outputs=[send_btn]
|
674 |
)
|
675 |
|
676 |
+
|
677 |
iframe = gr.HTML("<p>No Space created yet.</p>")
|
678 |
build_txt = gr.Textbox(label="Build Logs", lines=10, interactive=False, value="")
|
679 |
run_txt = gr.Textbox(label="Container Logs", lines=10, interactive=False, value="")
|
680 |
|
681 |
# The main event handler for the Send button
|
|
|
682 |
send_btn.click(
|
683 |
ai_workflow_chat,
|
684 |
inputs=[
|
|
|
702 |
)
|
703 |
|
704 |
# Link state variables to UI status displays (reactive updates)
|
|
|
705 |
workflow.change(lambda s: s, inputs=workflow, outputs=status_text)
|
|
|
706 |
repo_id.change(lambda r: r if r else "None", inputs=repo_id, outputs=repo_id_text)
|
707 |
|
708 |
|