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
Allow start/pause of streaming image input. Only access the webcam while it's needed #7228
Conversation
🪼 branch checks and previews
|
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
js/image/shared/Webcam.svelte
Outdated
@@ -180,19 +203,34 @@ | |||
event.stopPropagation(); | |||
options_open = false; | |||
} | |||
|
|||
$: console.log("webcam_accessed", webcam_accessed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will delete 🤦
js/image/shared/Webcam.svelte
Outdated
<WebcamIcon /> | ||
</span> | ||
<button on:click={async () => await access_webcam()} | ||
>{"Click to access webcam"}</button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be camel case for consistency
I could've sworn I made the change to set the progress tracker visibility to False when streaming from a webcam |
I'm pretty sure its a regression. We should do this for any streaming event, e.g. #7230 as well |
This looks great to me @freddyaboulton! My only feedback is that the clickable area to give access to the webcam is very small. I kept clicking the icon and was confused why it wasn't working. I'd suggest making this whole area clickable: |
@aliabid94 Yea I remember too. I think it was this PR - #6709 Maybe we accidentally merged a regression. |
Is the demo supposed to be using an audio component? Btw when I was running locally I did not see the progress bar but also I got this error after a while when streaming a webcam: |
Actually there was a visible progress bar only when using streaming from Interface, fixed in this PR in this commit: db019e4 |
db019e4
to
1395b21
Compare
Nice - confirmed it works! 🔥
Yea that's my bad - copy/pasted the wrong demo. I updated the PR description to include the correct one but also including it here import gradio as gr
import numpy as np
def flip(im):
return np.flipud(im)
with gr.Blocks() as demo:
with gr.Row():
input_img = gr.Image(sources=["webcam"])
output_img = gr.Image()
input_img.stream(flip, input_img, output_img)
demo.launch(share=True)
if __name__ == "__main__":
demo.launch()
Agreed - just pushed up a fix! Will wait for CI to pass before opening it up for broader review. |
js/image/shared/Webcam.svelte
Outdated
const func = mode === "image" ? take_picture : take_recording; | ||
func(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's avoid abbreviations like func
. Personally think this is more readable tbh
const func = mode === "image" ? take_picture : take_recording; | |
func(); | |
if (mode === "image") { | |
take_picture(); | |
} else { | |
take_recording(); | |
} |
js/image/shared/Webcam.svelte
Outdated
@@ -253,6 +282,10 @@ | |||
height: var(--size-full); | |||
} | |||
|
|||
.invisible { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, but we use the class name hide
throughout the codebase for display: none;
, for consistency would be nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM great work
Looks great @freddyaboulton. Small nit, I notice after taking a picture the input component quickly flashes back to the "click to access webcam" state before showing the taken picture. |
Maybe also fixes: #7230? |
b26b2c5
to
9255ecd
Compare
Thanks for the reviews everyone! Will merge the comments and flicker have been addressed. |
Description
Closes: #3642
Closes: #7230
If the webcam is an allowed image source, gradio will access the webcam as soon as the component is mounted on the page. There is also no way to stop gradio from accessing the webcam. This is #3642
When the webcam is an allowed source, users have to click into the image component to grant webcam access. This is what it looks like in that case:
After the webcam stops recording or taking a picture, gradio will stop using the webcam and revert back to the ^previous state.
Additionally, when
gr.Image(streaming=true)
, the webcam component will behave similarly to video recording. There will be a record and stop button at the bottom that users can use to stop the stream of images.Webcam Demo no streaming
Webcam Demo with streaming
Test streaming with this demo
EDIT:
Also fixes Interface streaming blocking the output, fixes: #7021
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh