Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
57 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
58 |
-
width =
|
59 |
-
height =
|
60 |
|
61 |
-
#
|
62 |
-
|
63 |
-
|
64 |
-
out = cv2.VideoWriter(output_path, fourcc, fps, (
|
65 |
|
66 |
-
while
|
67 |
ret, frame = cap.read()
|
68 |
if not ret:
|
69 |
break
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
73 |
|
74 |
cap.release()
|
75 |
out.release()
|
76 |
|
77 |
-
return output_path, "", ""
|
78 |
|
79 |
else:
|
80 |
-
#
|
81 |
frame = cv2.imread(file_path)
|
82 |
if frame is None:
|
83 |
-
return None, "Invalid image", ""
|
84 |
|
85 |
annotated = annotate_frame(frame)
|
86 |
-
|
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(
|