IbrahimHasani commited on
Commit
10696ac
1 Parent(s): 59ff21b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -1,9 +1,15 @@
1
  import gradio as gr
2
  import torch
 
 
 
 
 
 
3
  import numpy as np
4
  from transformers import AutoProcessor, AutoModel
5
  from PIL import Image
6
- from decord import VideoReader, cpu
7
 
8
  def sample_uniform_frame_indices(clip_len, seg_len):
9
  """
@@ -21,7 +27,7 @@ def sample_uniform_frame_indices(clip_len, seg_len):
21
  return np.array(indices).astype(np.int64)
22
 
23
  def read_video_decord(file_path, indices):
24
- vr = VideoReader(file_path, num_threads=1, ctx=cpu(0))
25
  video = vr.get_batch(indices).asnumpy()
26
  return video
27
 
@@ -62,6 +68,7 @@ def model_interface(uploaded_video, model_choice, activities):
62
 
63
  processor = AutoProcessor.from_pretrained(model_choice)
64
  model = AutoModel.from_pretrained(model_choice)
 
65
 
66
  activities_list = activities.split(",")
67
  inputs = processor(
 
1
  import gradio as gr
2
  import torch
3
+
4
+ print(f"Is CUDA available: {torch.cuda.is_available()}")
5
+ # True
6
+ print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
7
+ # Tesla T4
8
+
9
  import numpy as np
10
  from transformers import AutoProcessor, AutoModel
11
  from PIL import Image
12
+ from decord import VideoReader, gpu
13
 
14
  def sample_uniform_frame_indices(clip_len, seg_len):
15
  """
 
27
  return np.array(indices).astype(np.int64)
28
 
29
  def read_video_decord(file_path, indices):
30
+ vr = VideoReader(file_path, num_threads=1, ctx=gpu(0))
31
  video = vr.get_batch(indices).asnumpy()
32
  return video
33
 
 
68
 
69
  processor = AutoProcessor.from_pretrained(model_choice)
70
  model = AutoModel.from_pretrained(model_choice)
71
+ model = model.to("cuda")
72
 
73
  activities_list = activities.split(",")
74
  inputs = processor(