13ze commited on
Commit
35c3710
·
verified ·
1 Parent(s): 9f21e4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -20,9 +20,18 @@ with gr.Blocks() as demo:
20
  chat_input.submit(chat, chat_input, chat_output)
21
 
22
  with gr.Column():
23
- video = gr.Video(label="Seu vídeo", mirror_webcam=True)
24
  gr.Markdown("Clique no botão abaixo para iniciar sua câmera")
25
- webcam_button = gr.Button("Iniciar câmera")
26
- webcam_button.click(fn=None, inputs=None, outputs=video, _js="() => navigator.mediaDevices.getUserMedia({ video: true }).then(stream => { const video = document.querySelector('video'); video.srcObject = stream; video.play(); })")
 
 
 
 
 
 
 
 
 
 
27
 
28
  demo.launch(share=True)
 
20
  chat_input.submit(chat, chat_input, chat_output)
21
 
22
  with gr.Column():
 
23
  gr.Markdown("Clique no botão abaixo para iniciar sua câmera")
24
+ webcam_html = """
25
+ <video id='webcam' autoplay playsinline style='width: 100%;'></video>
26
+ <button onclick='startWebcam()'>Iniciar câmera</button>
27
+ <script>
28
+ async function startWebcam() {
29
+ const stream = await navigator.mediaDevices.getUserMedia({ video: true });
30
+ const video = document.getElementById('webcam');
31
+ video.srcObject = stream;
32
+ }
33
+ </script>
34
+ """
35
+ gr.HTML(webcam_html)
36
 
37
  demo.launch(share=True)