Commit
•
71f3eaf
1
Parent(s):
661db2c
Update app.py
Browse files
app.py
CHANGED
@@ -1,79 +1,68 @@
|
|
1 |
-
pip install soundfile
|
2 |
-
import torch
|
3 |
-
from transformers import pipeline
|
4 |
import streamlit as st
|
5 |
-
import
|
6 |
-
import
|
|
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
chunk_length_s=30,
|
17 |
-
device=device,
|
18 |
-
)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
seconds: float, always_include_hours: bool = False, decimal_marker: str = "."
|
24 |
-
):
|
25 |
-
if seconds is not None:
|
26 |
-
milliseconds = round(seconds * 1000.0)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
minutes = milliseconds // 60_000
|
32 |
-
milliseconds -= minutes * 60_000
|
33 |
-
|
34 |
-
seconds = milliseconds // 1_000
|
35 |
-
milliseconds -= seconds * 1_000
|
36 |
-
|
37 |
-
hours_marker = f"{hours:02d}:" if always_include_hours or hours > 0 else ""
|
38 |
-
return f"{hours_marker}{minutes:02d}:{seconds:02d}{decimal_marker}{milliseconds:03d}"
|
39 |
-
else:
|
40 |
-
# we have a malformed timestamp so just return it as is
|
41 |
-
return seconds
|
42 |
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
return_timestamps=return_timestamps,
|
52 |
-
)
|
53 |
-
text = outputs["text"]
|
54 |
-
if return_timestamps:
|
55 |
-
timestamps = outputs["chunks"]
|
56 |
-
timestamps = [
|
57 |
-
f"[{format_timestamp(chunk['timestamp'][0])} -> {format_timestamp(chunk['timestamp'][1])}] {chunk['text']}"
|
58 |
-
for chunk in timestamps
|
59 |
-
]
|
60 |
-
text = "\n".join(str(feature) for feature in timestamps)
|
61 |
-
return text
|
62 |
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
77 |
|
78 |
|
79 |
if __name__ == "__main__":
|
@@ -82,3 +71,4 @@ if __name__ == "__main__":
|
|
82 |
|
83 |
|
84 |
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
|
6 |
+
def images_to_video(image_folder_path, output_video_path, fps):
|
7 |
+
# Get the list of image files
|
8 |
+
image_files = sorted(os.listdir(image_folder_path))
|
9 |
+
image_files = [f for f in image_files if f.endswith(('.jpg', '.jpeg', '.png'))]
|
10 |
|
11 |
+
# Read the first image to get dimensions
|
12 |
+
first_image = cv2.imread(os.path.join(image_folder_path, image_files[0]))
|
13 |
+
height, width, _ = first_image.shape
|
14 |
|
15 |
+
# Create video writer object
|
16 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
17 |
+
video_writer = cv2.VideoWriter(output_video_path, fourcc, fps, (width, height))
|
|
|
|
|
|
|
18 |
|
19 |
+
# Loop through images and write to video
|
20 |
+
for image_file in image_files:
|
21 |
+
image_path = os.path.join(image_folder_path, image_file)
|
22 |
+
frame = cv2.imread(image_path)
|
23 |
+
video_writer.write(frame)
|
24 |
|
25 |
+
# Release video writer
|
26 |
+
video_writer.release()
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
def main():
|
29 |
+
st.title("Image to Video Converter")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
# File uploader for selecting images
|
32 |
+
st.write("Please upload the images you want to convert to a video:")
|
33 |
+
uploaded_files = st.file_uploader("Upload Images", accept_multiple_files=True, type=["jpg", "jpeg", "png"])
|
34 |
|
35 |
+
if uploaded_files:
|
36 |
+
st.write("You've uploaded the following images:")
|
37 |
+
for uploaded_file in uploaded_files:
|
38 |
+
st.image(uploaded_file)
|
39 |
|
40 |
+
# Parameters for video creation
|
41 |
+
fps = st.number_input("Frames per Second (FPS)", value=24, min_value=1)
|
42 |
+
output_video_name = st.text_input("Output Video Name (include .mp4)", "output.mp4")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
# Convert images to video
|
45 |
+
if st.button("Convert to Video"):
|
46 |
+
temp_folder = "./temp_images"
|
47 |
+
os.makedirs(temp_folder, exist_ok=True)
|
48 |
|
49 |
+
# Save uploaded images to a temporary folder
|
50 |
+
for i, uploaded_file in enumerate(uploaded_files):
|
51 |
+
file_path = os.path.join(temp_folder, f"image_{i}.png")
|
52 |
+
with open(file_path, "wb") as f:
|
53 |
+
f.write(uploaded_file.getbuffer())
|
54 |
|
55 |
+
# Convert images to video
|
56 |
+
images_to_video(temp_folder, output_video_name, fps)
|
57 |
|
58 |
+
# Display download link for the video
|
59 |
+
st.markdown(f"Download the video [here](./{output_video_name})")
|
60 |
|
61 |
+
# Clean up temporary folder
|
62 |
+
for file_name in os.listdir(temp_folder):
|
63 |
+
file_path = os.path.join(temp_folder, file_name)
|
64 |
+
os.remove(file_path)
|
65 |
+
os.rmdir(temp_folder)
|
66 |
|
67 |
|
68 |
if __name__ == "__main__":
|
|
|
71 |
|
72 |
|
73 |
|
74 |
+
|