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

enabled sending the same image for various browsers #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions st_multimodal_chatinput/frontend/src/MultimodalChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MultimodalChatInput extends StreamlitComponentBase<State> {
cursor: "not-allowed",
};

private fileInputRef = React.createRef<HTMLInputElement>();

public state: State = {
uploadedFiles: [],
textInput: "",
Expand All @@ -34,6 +36,10 @@ class MultimodalChatInput extends StreamlitComponentBase<State> {

handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.processFiles(event.target.files);

if (this.fileInputRef.current) {
this.fileInputRef.current.value = ""; // Reset the file input to allow same file selection
}
};

handleRemoveFile = (indexToRemove: number) => {
Expand All @@ -53,6 +59,11 @@ class MultimodalChatInput extends StreamlitComponentBase<State> {
uploadedFiles: [],
textInput: ""
});

// Reset the file input after submission
if (this.fileInputRef.current) {
this.fileInputRef.current.value = "";
}
};

handlePaste = (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
Expand Down Expand Up @@ -92,10 +103,10 @@ class MultimodalChatInput extends StreamlitComponentBase<State> {
};

public render = (): ReactNode => {
const disabled = this.props.args["disabled"]
const placeholder = this.props.args["placeholder"]
const disabled = this.props.args["disabled"];
const placeholder = this.props.args["placeholder"];
const isDisabled = this.props.disabled || disabled;
const width = this.props.width
const width = this.props.width;

return (
<div style={{ position: "relative", display: "flex", flexDirection: "column", border: "1px solid gray", borderRadius: "8px", padding: "8px", width: width }} >
Expand Down Expand Up @@ -123,7 +134,15 @@ class MultimodalChatInput extends StreamlitComponentBase<State> {
{/* File Upload Button */}
<label style={{ marginRight: "10px", ...(isDisabled ? this.disabledStyle : {}) }}>
📎
<input disabled={isDisabled} type="file" accept="image/*,.pdf,.docx,.xlsx" multiple onChange={this.handleFileChange} style={{ display: "none" }} />
<input
disabled={isDisabled}
ref={this.fileInputRef} // Reference the input element
type="file"
accept="image/*,.pdf,.docx,.xlsx"
multiple
onChange={this.handleFileChange}
style={{ display: "none" }}
/>
</label>

{/* Textarea for Chat */}
Expand Down