biplab2008 commited on
Commit
7862f4b
·
verified ·
1 Parent(s): d6772c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -19
app.py CHANGED
@@ -1,31 +1,77 @@
1
- #from transformers import pipeline
2
-
3
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
4
 
5
- #asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
6
- #classifier = pipeline("text-classification")
 
 
 
 
 
 
 
7
 
 
 
 
 
 
 
8
 
9
- def speech_to_text():
10
- text = 'running speech to text'
11
- return text
12
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- def text_to_sentiment():
15
- return 'running text to sentiment'
16
 
 
 
 
 
 
 
17
 
18
- demo = gr.Blocks()
 
19
 
20
- with demo:
21
- audio_file = gr.File(file_count='multiple')
22
- text = gr.Textbox()
23
- label = gr.Label()
 
 
24
 
25
- b1 = gr.Button("Recognize Speech")
26
- b2 = gr.Button("Classify Sentiment")
27
 
28
- b1.click(speech_to_text, inputs=audio_file, outputs=text)
29
- b2.click(text_to_sentiment, inputs=text, outputs=label)
30
 
31
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
 
2
  import gradio as gr
3
+ import imutils
4
+ import numpy as np
5
+ import torch
6
+ from PIL import Image
7
+
8
+ def parse_video(video_file):
9
+ """A utility to parse the input videos.
10
+ Reference: https://pyimagesearch.com/2018/11/12/yolo-object-detection-with-opencv/
11
+ """
12
+ vs = cv2.VideoCapture(video_file)
13
 
14
+ # try to determine the total number of frames in the video file
15
+ try:
16
+ prop = (
17
+ cv2.cv.CV_CAP_PROP_FRAME_COUNT
18
+ if imutils.is_cv2()
19
+ else cv2.CAP_PROP_FRAME_COUNT
20
+ )
21
+ total = int(vs.get(prop))
22
+ print("[INFO] {} total frames in video".format(total))
23
 
24
+ # an error occurred while trying to determine the total
25
+ # number of frames in the video file
26
+ except:
27
+ print("[INFO] could not determine # of frames in video")
28
+ print("[INFO] no approx. completion time can be provided")
29
+ total = -1
30
 
31
+ frames = []
 
 
32
 
33
+ # loop over frames from the video file stream
34
+ while True:
35
+ # read the next frame from the file
36
+ (grabbed, frame) = vs.read()
37
+ if frame is not None:
38
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
39
+ frames.append(frame)
40
+ # if the frame was not grabbed, then we have reached the end
41
+ # of the stream
42
+ if not grabbed:
43
+ break
44
 
45
+ return frames
 
46
 
47
+ def pil_parser(frames):
48
+ X = []
49
+ frames = np.arange(2,62,2)
50
+ use_transform : transforms.Compose =transforms.Compose([transforms.Resize([256, 342]),
51
+ transforms.ToTensor(),
52
+ transforms.Normalize(mean=[0.5], std=[0.5])])
53
 
54
+ for i in frames:
55
+ image = Image.fromarray(dummy_frames[i]).convert('L')
56
 
57
+ if use_transform is not None:
58
+ image = use_transform(image)
59
+ else:
60
+ image = transforms.ToTensor()(image)
61
+ X.append(image)
62
+ X = torch.stack(X, dim=1).unsqueeze(0)
63
 
64
+ return str(X.shape)
 
65
 
 
 
66
 
67
+ gr.Interface(
68
+ fn=infer,
69
+ inputs=gr.Video(),
70
+ outputs=['text'],
71
+ title="Viscosity Regression From Video Data",
72
+ description=(
73
+ "Gradio demo for Video Regression"
74
+ ),
75
+ allow_flagging='never',
76
+
77
+ ).launch()