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

Switches to multilingual Elevenlabs #181

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Show dropdown with image filename
  • Loading branch information
jp-ipu committed Nov 12, 2023
commit aef4e7f5257f670d87b2e2f341ff0b7ec72f880f
60 changes: 50 additions & 10 deletions app/src/components/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default function MessageInput(props: MessageInputProps) {
const [speechError, setSpeechError] = useState<string | null>(null);
const [imageUrl, setImageUrl] = useState(null);
const [isImageUploading, setIsImageUploading] = useState(false);
const [uploadedImageName, setUploadedImageName] = useState('');
const [showImageNameDropdown, setShowImageNameDropdown] = useState(false);
const hasVerticalSpace = useMediaQuery('(min-height: 1000px)');
const [useOpenAIWhisper] = useOption<boolean>('speech-recognition', 'use-whisper');
const [openAIApiKey] = useOption<string>('openai', 'apiKey');
Expand Down Expand Up @@ -204,6 +206,7 @@ export default function MessageInput(props: MessageInputProps) {
const file = event.target.files[0];
if (file) {
setIsImageUploading(true);
setUploadedImageName(file.name);
const reader = new FileReader();

reader.onload = (loadEvent) => {
Expand All @@ -217,12 +220,23 @@ export default function MessageInput(props: MessageInputProps) {
// FIXME: Add error to UI
console.log('Error uploading image: ', error);
setIsImageUploading(false);
setUploadedImageName('');
}

reader.readAsDataURL(file);
}
};

function handleMouseEnter() {
if (imageUrl) {
setShowImageNameDropdown(true);
}
}

function handleMouseLeave() {
setShowImageNameDropdown(false);
}

const rightSection = useMemo(() => {
return (
<div style={{
Expand Down Expand Up @@ -280,15 +294,41 @@ export default function MessageInput(props: MessageInputProps) {
ref={fileInputRef}
/>

<ActionIcon size="xl"
onClick={() => fileInputRef.current.click()}
disabled={isImageUploading}>
{isImageUploading ? (
<i className="fa fa-ellipsis-h" style={{ fontSize: '90%' }} />
) : (
<i className="fa fa-camera" style={{ fontSize: '90%' }} />
)}
</ActionIcon>
<div onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
<Popover width={200} position="bottom" withArrow shadow="md" opened={showImageNameDropdown}>
<Popover.Target>
<ActionIcon
size="xl"
onClick={() => fileInputRef.current.click()}
disabled={isImageUploading}
>
{isImageUploading ? (
<i className="fa fa-ellipsis-h" style={{ fontSize: '90%' }} />
) : uploadedImageName ? (
<i className="fa fa-check" style={{ fontSize: '90%' }} />
) : (
<i className="fa fa-camera" style={{ fontSize: '90%' }} />
)}
</ActionIcon>
</Popover.Target>
<Popover.Dropdown>
<div style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
}}>
<p style={{
fontFamily: `"Work Sans", sans-serif`,
fontSize: '0.9rem',
textAlign: 'center',
marginBottom: '0.5rem',
}}>
{uploadedImageName}
</p>
</div>
</Popover.Dropdown>
</Popover>
</div>

<ActionIcon size="xl"
onClick={onSubmit}
Expand All @@ -299,7 +339,7 @@ export default function MessageInput(props: MessageInputProps) {
)}
</div>
);
}, [recording, transcribing, isImageUploading, imageUrl, onSubmit, onSpeechStart, props.disabled, context.generating, speechError, onHideSpeechError, showMicrophoneButton]);
}, [recording, transcribing, isImageUploading, imageUrl, showImageNameDropdown, onSubmit, onSpeechStart, props.disabled, context.generating, speechError, onHideSpeechError, showMicrophoneButton]);

const disabled = context.generating;

Expand Down