Spaces:
Running on Zero
Running on Zero
ui: default to Completion+code (matches cached trace); clear textbox on switch to Chat, restore seed on switch back if empty
Browse files- demo/srt_introspect_app.py +35 -6
demo/srt_introspect_app.py
CHANGED
|
@@ -760,19 +760,24 @@ def build_app() -> gr.Blocks:
|
|
| 760 |
with gr.Row():
|
| 761 |
with gr.Column(scale=3):
|
| 762 |
mode = gr.Radio(
|
| 763 |
-
choices=["
|
| 764 |
-
value="
|
| 765 |
label="Input mode",
|
| 766 |
info=(
|
| 767 |
-
"Chat: type a question or instruction naturally; "
|
| 768 |
-
"we wrap it as User:/Assistant: for the base model. "
|
| 769 |
"Completion: feed the prompt raw (good for code, "
|
| 770 |
-
"narrative, or mid-sentence continuations)."
|
|
|
|
|
|
|
| 771 |
),
|
| 772 |
)
|
| 773 |
prompt = gr.Textbox(
|
| 774 |
label="Prompt",
|
| 775 |
-
value=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
lines=6,
|
| 777 |
)
|
| 778 |
with gr.Column(scale=2):
|
|
@@ -822,6 +827,30 @@ def build_app() -> gr.Blocks:
|
|
| 822 |
)
|
| 823 |
stop.click(fn=None, cancels=[gen_event])
|
| 824 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 825 |
gr.Markdown(f"""
|
| 826 |
---
|
| 827 |
|
|
|
|
| 760 |
with gr.Row():
|
| 761 |
with gr.Column(scale=3):
|
| 762 |
mode = gr.Radio(
|
| 763 |
+
choices=["Completion", "Chat"],
|
| 764 |
+
value="Completion",
|
| 765 |
label="Input mode",
|
| 766 |
info=(
|
|
|
|
|
|
|
| 767 |
"Completion: feed the prompt raw (good for code, "
|
| 768 |
+
"narrative, or mid-sentence continuations). "
|
| 769 |
+
"Chat: type a question or instruction naturally; "
|
| 770 |
+
"we wrap it as User:/Assistant: for the base model."
|
| 771 |
),
|
| 772 |
)
|
| 773 |
prompt = gr.Textbox(
|
| 774 |
label="Prompt",
|
| 775 |
+
value=(
|
| 776 |
+
"def quicksort(arr):\n"
|
| 777 |
+
" if len(arr) <= 1:\n"
|
| 778 |
+
" return arr\n"
|
| 779 |
+
" pivot = arr[len(arr) // 2]\n"
|
| 780 |
+
),
|
| 781 |
lines=6,
|
| 782 |
)
|
| 783 |
with gr.Column(scale=2):
|
|
|
|
| 827 |
)
|
| 828 |
stop.click(fn=None, cancels=[gen_event])
|
| 829 |
|
| 830 |
+
# Default code prompt only makes sense in Completion mode. When the
|
| 831 |
+
# user switches to Chat, blank the textbox so they don't try to chat
|
| 832 |
+
# with `def quicksort(...)`; when they switch back to Completion,
|
| 833 |
+
# restore the code seed so the textbox isn't stranded empty.
|
| 834 |
+
_COMPLETION_DEFAULT = (
|
| 835 |
+
"def quicksort(arr):\n"
|
| 836 |
+
" if len(arr) <= 1:\n"
|
| 837 |
+
" return arr\n"
|
| 838 |
+
" pivot = arr[len(arr) // 2]\n"
|
| 839 |
+
)
|
| 840 |
+
|
| 841 |
+
def _on_mode_change(new_mode: str, current: str):
|
| 842 |
+
if (new_mode or "").lower().startswith("chat"):
|
| 843 |
+
# Only clear if the user hasn't edited the default code seed.
|
| 844 |
+
if current.strip() == _COMPLETION_DEFAULT.strip():
|
| 845 |
+
return gr.update(value="", placeholder="Ask anything…")
|
| 846 |
+
return gr.update(placeholder="Ask anything…")
|
| 847 |
+
# Switched to Completion: restore code seed only if textbox is empty.
|
| 848 |
+
if not current.strip():
|
| 849 |
+
return gr.update(value=_COMPLETION_DEFAULT, placeholder=None)
|
| 850 |
+
return gr.update(placeholder=None)
|
| 851 |
+
|
| 852 |
+
mode.change(_on_mode_change, inputs=[mode, prompt], outputs=[prompt])
|
| 853 |
+
|
| 854 |
gr.Markdown(f"""
|
| 855 |
---
|
| 856 |
|