spookyuser
commited on
Commit
·
fb39589
1
Parent(s):
93dd267
Refactor so that videos arent the same file
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import uuid
|
|
7 |
import shutil
|
8 |
|
9 |
|
10 |
-
output_dir = Path("temp/")
|
11 |
output_dir.mkdir(exist_ok=True, parents=True)
|
12 |
|
13 |
os.chdir(
|
@@ -16,7 +16,7 @@ os.chdir(
|
|
16 |
|
17 |
|
18 |
class SpotifyApi:
|
19 |
-
spotify_directory = Path(
|
20 |
final_directory = output_dir
|
21 |
|
22 |
def __init__(self):
|
@@ -50,11 +50,15 @@ class SpotifyApi:
|
|
50 |
):
|
51 |
for file in files:
|
52 |
if file.endswith(".mp3"):
|
53 |
-
final_mp3 =
|
54 |
-
self.final_directory / self.foldername
|
55 |
-
|
56 |
-
|
|
|
57 |
shutil.copy(os.path.join(root, file), final_mp3)
|
|
|
|
|
|
|
58 |
return final_mp3.as_posix()
|
59 |
|
60 |
|
@@ -71,14 +75,19 @@ def add_static_image_to_audio(image, audio) -> str:
|
|
71 |
"""Create and save a video file to `output_path` after
|
72 |
combining a static image that is located in `image_path`
|
73 |
with an audio file in `audio_path`"""
|
|
|
|
|
|
|
|
|
|
|
74 |
audio_clip = AudioFileClip(audio)
|
75 |
image_clip = ImageClip(image)
|
76 |
video_clip = image_clip.set_audio(audio_clip)
|
77 |
video_clip.duration = audio_clip.duration
|
78 |
video_clip.fps = 1
|
79 |
-
path = Path(
|
80 |
video_clip.write_videofile(path)
|
81 |
-
return path
|
82 |
|
83 |
|
84 |
def get_stable_diffusion_image(prompt) -> str:
|
|
|
7 |
import shutil
|
8 |
|
9 |
|
10 |
+
output_dir = Path("temp/").absolute()
|
11 |
output_dir.mkdir(exist_ok=True, parents=True)
|
12 |
|
13 |
os.chdir(
|
|
|
16 |
|
17 |
|
18 |
class SpotifyApi:
|
19 |
+
spotify_directory = Path("spotify")
|
20 |
final_directory = output_dir
|
21 |
|
22 |
def __init__(self):
|
|
|
50 |
):
|
51 |
for file in files:
|
52 |
if file.endswith(".mp3"):
|
53 |
+
final_mp3 = (
|
54 |
+
Path(self.final_directory / self.foldername)
|
55 |
+
.with_suffix(".mp3")
|
56 |
+
.absolute()
|
57 |
+
)
|
58 |
shutil.copy(os.path.join(root, file), final_mp3)
|
59 |
+
shutil.rmtree(
|
60 |
+
Path(self.spotify_directory / self.foldername).absolute()
|
61 |
+
)
|
62 |
return final_mp3.as_posix()
|
63 |
|
64 |
|
|
|
75 |
"""Create and save a video file to `output_path` after
|
76 |
combining a static image that is located in `image_path`
|
77 |
with an audio file in `audio_path`"""
|
78 |
+
# Generate a random folder name and change directories to there
|
79 |
+
foldername = str(uuid.uuid4())[:8]
|
80 |
+
vid_output_dir = Path(output_dir / foldername)
|
81 |
+
vid_output_dir.mkdir(exist_ok=True, parents=True)
|
82 |
+
os.chdir(vid_output_dir)
|
83 |
audio_clip = AudioFileClip(audio)
|
84 |
image_clip = ImageClip(image)
|
85 |
video_clip = image_clip.set_audio(audio_clip)
|
86 |
video_clip.duration = audio_clip.duration
|
87 |
video_clip.fps = 1
|
88 |
+
path = Path("output.mp4").as_posix()
|
89 |
video_clip.write_videofile(path)
|
90 |
+
return path
|
91 |
|
92 |
|
93 |
def get_stable_diffusion_image(prompt) -> str:
|