Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the color of placeholder in a disabled textbox to gray instead of black, and disable typing while a response is generating in gr.ChatInterface, allow gr.MultimodalTextbox to accept string values #9328

Merged
merged 15 commits into from
Sep 12, 2024
6 changes: 6 additions & 0 deletions .changeset/wet-memes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/textbox": patch
"gradio": patch
---

fix:Set the color of placeholder in a disabled textbox to gray instead of black, and disable typing while a response is generating in `gr.ChatInterface`
19 changes: 15 additions & 4 deletions gradio/chat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from gradio.components.multimodal_textbox import MultimodalData
from gradio.events import Dependency, on
from gradio.helpers import create_examples as Examples # noqa: N812
from gradio.helpers import special_args
from gradio.helpers import special_args, update
from gradio.layouts import Accordion, Group, Row
from gradio.routes import Request
from gradio.themes import ThemeClass as Theme
Expand Down Expand Up @@ -295,6 +295,12 @@ def _setup_events(self) -> None:
Literal["full", "minimal", "hidden"], self.show_progress
),
)
.then(
lambda: update(value=None, interactive=True, placeholder=""),
None,
self.textbox,
show_api=False,
)
)
self._setup_stop_events(submit_triggers, submit_event)

Expand Down Expand Up @@ -430,11 +436,16 @@ async def api_fn(message, history, *args, **kwargs):

def _clear_and_save_textbox(
self, message: str | dict
) -> tuple[str | dict, str | MultimodalData]:
) -> tuple[Textbox | MultimodalTextbox, str | MultimodalData]:
placeholder = message if isinstance(message, str) else message.get("text", "")
if self.multimodal:
return {"text": "", "files": []}, MultimodalData(**cast(dict, message))
return MultimodalTextbox(
{"text": "", "files": []}, interactive=False, placeholder=placeholder
), MultimodalData(**cast(dict, message))
else:
return "", cast(str, message)
return Textbox("", interactive=False, placeholder=placeholder), cast(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the placeholder because we've already cleared the textbox and the user message is displayed in the chatbot.

Minor point though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah okay I can just get rid of it, no strong feelings on my part

str, message
)

def _append_multimodal_history(
self,
Expand Down
1 change: 0 additions & 1 deletion js/textbox/shared/Textbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@
}
input:disabled,
textarea:disabled {
-webkit-text-fill-color: var(--body-text-color);
-webkit-opacity: 1;
opacity: 1;
}
Expand Down
Loading