lampongyuen commited on
Commit
69bd671
·
1 Parent(s): bd8f7dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -61
app.py CHANGED
@@ -1,65 +1,21 @@
1
  import gradio as gr
2
  import cv2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- def color_to_gray(img):
5
- new_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
6
- return new_img
7
 
8
-
9
-
10
- def predict(video_in, image_in_video, image_in_img):
11
- if video_in == None and image_in_video == None and image_in_img == None:
12
- raise gr.Error("Please upload a video or image.")
13
- if image_in_video or image_in_img:
14
- print("image", image_in_video, image_in_img)
15
- image = image_in_video or image_in_img
16
- return image
17
-
18
- return video_in
19
-
20
-
21
- def toggle(choice):
22
- if choice == "webcam":
23
- return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
24
- else:
25
- return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
26
-
27
-
28
- with gr.Blocks() as blocks:
29
- gr.Markdown("### Video or Image? WebCam or Upload?""")
30
- with gr.Tab("Video") as tab:
31
- with gr.Row():
32
- with gr.Column():
33
- video_or_file_opt = gr.Radio(["webcam", "upload"], value="webcam",
34
- label="How would you like to upload your video?")
35
- video_in = gr.Video(source="webcam", include_audio=False)
36
- video_or_file_opt.change(fn=lambda s: gr.update(source=s, value=None), inputs=video_or_file_opt,
37
- outputs=video_in, queue=False, show_progress=False)
38
- with gr.Column():
39
- video_out = gr.Video()
40
- run_btn = gr.Button("Run")
41
- run_btn.click(fn=predict, inputs=[video_in], outputs=[video_out])
42
- gr.Examples(fn=predict, examples=[], inputs=[
43
- video_in], outputs=[video_out])
44
-
45
- with gr.Tab("Image"):
46
- with gr.Row():
47
- with gr.Column():
48
- image_or_file_opt = gr.Radio(["webcam", "file"], value="webcam",
49
- label="How would you like to upload your image?")
50
- image_in_video = gr.Image(source="webcam", type="filepath")
51
- image_in_img = gr.Image(
52
- source="upload", visible=False, type="filepath")
53
-
54
- image_or_file_opt.change(fn=toggle, inputs=[image_or_file_opt],
55
- outputs=[image_in_video, image_in_img], queue=False, show_progress=False)
56
- with gr.Column():
57
- image_out = gr.Image()
58
- run_btn = gr.Button("Run")
59
- run_btn.click(fn=predict, inputs=[
60
- image_in_img, image_in_video], outputs=[image_out])
61
- gr.Examples(fn=predict, examples=[], inputs=[
62
- image_in_img, image_in_video], outputs=[image_out])
63
-
64
- blocks.queue()
65
- blocks.launch()
 
1
  import gradio as gr
2
  import cv2
3
+ import numpy as np
4
+ invideo = cv2.VideoCapture('https://www.youtube.com/watch?v=5WbClF6WXRE')
5
+ cv2.namedWindow('Live cam',cv.WINDOW_NORMAL)
6
+ if not invideo.isOpened():
7
+ print("Cannot open camera")
8
+ exit()
9
+ while True:
10
+ # Capture frame-by-frame
11
+ read_correct, frame = invideo.read()
12
+ if not read_correct:
13
+ print("cannot read correctly")
14
+ break
15
+ cv2.imshow('Video Capture from Camera', frame)
16
+ if cv.waitKey(25) == ord('q'):
17
+ break
18
+ invideo.release()
19
+ cv.destroyAllWindows()
20
 
 
 
 
21