krishnasivaborra commited on
Commit
cfe992b
·
verified ·
1 Parent(s): 22bdd2f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import cv2
4
+ from PIL import Image
5
+ import tempfile
6
+
7
+ def images_to_video(image_files, fps):
8
+ temp_dir = tempfile.mkdtemp()
9
+ image_paths = []
10
+
11
+ # Save uploaded images to temp folder
12
+ for idx, file in enumerate(image_files):
13
+ img = Image.open(file.name).convert("RGB")
14
+ img_path = os.path.join(temp_dir, f"img_{idx:03d}.png")
15
+ img.save(img_path)
16
+ image_paths.append(img_path)
17
+
18
+ if not image_paths:
19
+ return "No images uploaded!"
20
+
21
+ # Get size from first image
22
+ first_image = cv2.imread(image_paths[0])
23
+ height, width, _ = first_image.shape
24
+
25
+ video_path = os.path.join(temp_dir, "output_video.mp4")
26
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
27
+ video = cv2.VideoWriter(video_path, fourcc, fps, (width, height))
28
+
29
+ for path in image_paths:
30
+ img = cv2.imread(path)
31
+ video.write(img)
32
+
33
+ video.release()
34
+ return video_path
35
+
36
+ # Gradio interface
37
+ iface = gr.Interface(
38
+ fn=images_to_video,
39
+ inputs=[
40
+ gr.File(file_types=["image"], file_count="multiple", label="Upload Images"),
41
+ gr.Slider(minimum=1, maximum=60, value=10, label="FPS (frames per second)")
42
+ ],
43
+ outputs=gr.Video(label="Generated Video"),
44
+ title="🖼️➡️🎥 Image to Video Converter",
45
+ description="Upload images and turn them into a video. Because who has time for manual editing?"
46
+ )
47
+
48
+ if __name__ == "__main__":
49
+ iface.launch()