Sakibrumu commited on
Commit
58a562d
·
verified ·
1 Parent(s): 7de158e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -53,38 +53,41 @@ def process_input(input_file):
53
 
54
  if ext in ['.mp4', '.avi', '.mov']:
55
  cap = cv2.VideoCapture(file_path)
56
- fourcc = cv2.VideoWriter_fourcc(*'mp4v')
 
 
 
57
  fps = cap.get(cv2.CAP_PROP_FPS)
58
- width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
59
- height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
60
 
61
- # Output path
62
- timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
63
- output_path = f"annotated_{timestamp}.mp4"
64
- out = cv2.VideoWriter(output_path, fourcc, fps, (640, 640))
65
 
66
- while cap.isOpened():
67
  ret, frame = cap.read()
68
  if not ret:
69
  break
70
- annotated = annotate_frame(frame)
71
- annotated_resized = cv2.resize(annotated, (640, 640))
72
- out.write(cv2.cvtColor(annotated_resized, cv2.COLOR_RGB2BGR))
 
73
 
74
  cap.release()
75
  out.release()
76
 
77
- return output_path, "", ""
78
 
79
  else:
80
- # Image case
81
  frame = cv2.imread(file_path)
82
  if frame is None:
83
- return None, "Invalid image", ""
84
 
85
  annotated = annotate_frame(frame)
86
- pil_img = Image.fromarray(annotated)
87
- return pil_img, "", ""
88
 
89
 
90
  interface = gr.Interface(
 
53
 
54
  if ext in ['.mp4', '.avi', '.mov']:
55
  cap = cv2.VideoCapture(file_path)
56
+
57
+ if not cap.isOpened():
58
+ return None, "Could not open video file", ""
59
+
60
  fps = cap.get(cv2.CAP_PROP_FPS)
61
+ width = 640
62
+ height = 640
63
 
64
+ # Generate safe output path
65
+ output_path = f"annotated_output.mp4"
66
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
67
+ out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
68
 
69
+ while True:
70
  ret, frame = cap.read()
71
  if not ret:
72
  break
73
+ frame_resized = cv2.resize(frame, (640, 640))
74
+ annotated_frame = annotate_frame(frame_resized)
75
+ bgr_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_RGB2BGR)
76
+ out.write(bgr_frame)
77
 
78
  cap.release()
79
  out.release()
80
 
81
+ return output_path, "Bangla text in video (see frames)", "OCR confidence displayed on frames"
82
 
83
  else:
84
+ # Handle image
85
  frame = cv2.imread(file_path)
86
  if frame is None:
87
+ return None, "Invalid image file", ""
88
 
89
  annotated = annotate_frame(frame)
90
+ return Image.fromarray(annotated), "Bangla text in image", ""
 
91
 
92
 
93
  interface = gr.Interface(