Upload 3 files
Browse files- README.md +1 -1
- app.py +30 -3
- requirements.txt +1 -1
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🎬
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.44.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
app.py
CHANGED
@@ -50,9 +50,20 @@ def extract_frames_from_video(video_path, max_frames=30):
|
|
50 |
timestamps = []
|
51 |
|
52 |
try:
|
|
|
53 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
|
|
|
|
|
|
54 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
frame_count = 0
|
58 |
extracted_count = 0
|
@@ -68,10 +79,12 @@ def extract_frames_from_video(video_path, max_frames=30):
|
|
68 |
frames.append(Image.fromarray(frame_rgb))
|
69 |
timestamps.append(extracted_count)
|
70 |
extracted_count += 1
|
|
|
71 |
|
72 |
frame_count += 1
|
73 |
|
74 |
cap.release()
|
|
|
75 |
return frames, timestamps
|
76 |
except Exception as e:
|
77 |
print(f"Error extracting frames: {e}")
|
@@ -226,16 +239,30 @@ def process_video_with_minicpm(video_file):
|
|
226 |
try:
|
227 |
start_time = time.time()
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
# Extract frames
|
230 |
update_status = "Extracting frames from video..."
|
231 |
-
frames, timestamps = extract_frames_from_video(
|
232 |
|
233 |
if not frames:
|
234 |
return "Failed to extract frames from video.", "", ""
|
235 |
|
236 |
# Extract audio
|
237 |
update_status = "Extracting audio from video..."
|
238 |
-
audio_path = extract_audio_from_video(
|
239 |
|
240 |
# Analyze with MiniCPM-o
|
241 |
update_status = "Analyzing content with MiniCPM-o..."
|
|
|
50 |
timestamps = []
|
51 |
|
52 |
try:
|
53 |
+
print(f"Attempting to extract frames from: {video_path}")
|
54 |
cap = cv2.VideoCapture(video_path)
|
55 |
+
|
56 |
+
if not cap.isOpened():
|
57 |
+
print(f"Failed to open video: {video_path}")
|
58 |
+
return [], []
|
59 |
+
|
60 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
61 |
+
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
62 |
+
duration = total_frames / fps if fps > 0 else 0
|
63 |
+
|
64 |
+
print(f"Video info - FPS: {fps}, Total frames: {total_frames}, Duration: {duration:.2f}s")
|
65 |
+
|
66 |
+
frame_interval = max(1, int(fps)) # Extract 1 frame per second, minimum 1
|
67 |
|
68 |
frame_count = 0
|
69 |
extracted_count = 0
|
|
|
79 |
frames.append(Image.fromarray(frame_rgb))
|
80 |
timestamps.append(extracted_count)
|
81 |
extracted_count += 1
|
82 |
+
print(f"Extracted frame {extracted_count} at {frame_count}/{total_frames}")
|
83 |
|
84 |
frame_count += 1
|
85 |
|
86 |
cap.release()
|
87 |
+
print(f"Successfully extracted {len(frames)} frames")
|
88 |
return frames, timestamps
|
89 |
except Exception as e:
|
90 |
print(f"Error extracting frames: {e}")
|
|
|
239 |
try:
|
240 |
start_time = time.time()
|
241 |
|
242 |
+
# Handle both file object and string path
|
243 |
+
if hasattr(video_file, 'name'):
|
244 |
+
video_path = video_file.name
|
245 |
+
else:
|
246 |
+
video_path = video_file
|
247 |
+
|
248 |
+
# Debug: Check what we received
|
249 |
+
print(f"Video input type: {type(video_file)}")
|
250 |
+
print(f"Video path: {video_path}")
|
251 |
+
|
252 |
+
# Validate file exists
|
253 |
+
if not os.path.exists(video_path):
|
254 |
+
return f"Video file not found: {video_path}", "", ""
|
255 |
+
|
256 |
# Extract frames
|
257 |
update_status = "Extracting frames from video..."
|
258 |
+
frames, timestamps = extract_frames_from_video(video_path)
|
259 |
|
260 |
if not frames:
|
261 |
return "Failed to extract frames from video.", "", ""
|
262 |
|
263 |
# Extract audio
|
264 |
update_status = "Extracting audio from video..."
|
265 |
+
audio_path = extract_audio_from_video(video_path)
|
266 |
|
267 |
# Analyze with MiniCPM-o
|
268 |
update_status = "Analyzing content with MiniCPM-o..."
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
torch>=2.1.0
|
2 |
transformers>=4.35.0
|
3 |
-
gradio>=4.
|
4 |
opencv-python>=4.8.0
|
5 |
numpy>=1.24.0
|
6 |
pillow>=10.0.0
|
|
|
1 |
torch>=2.1.0
|
2 |
transformers>=4.35.0
|
3 |
+
gradio>=4.44.0
|
4 |
opencv-python>=4.8.0
|
5 |
numpy>=1.24.0
|
6 |
pillow>=10.0.0
|