spookyuser
commited on
Commit
•
89b6dcb
1
Parent(s):
fe1ef04
Add python input option - yay!
Browse files- .gitignore +2 -0
- Pipfile +11 -0
- app.py +55 -6
- requirements.txt +2 -1
.gitignore
CHANGED
@@ -167,3 +167,5 @@ cython_debug/
|
|
167 |
#.idea/
|
168 |
|
169 |
*.DS_STORE
|
|
|
|
|
|
167 |
#.idea/
|
168 |
|
169 |
*.DS_STORE
|
170 |
+
spotify.rc
|
171 |
+
spotify/
|
Pipfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[[source]]
|
2 |
+
url = "https://pypi.org/simple"
|
3 |
+
verify_ssl = true
|
4 |
+
name = "pypi"
|
5 |
+
|
6 |
+
[packages]
|
7 |
+
|
8 |
+
[dev-packages]
|
9 |
+
|
10 |
+
[requires]
|
11 |
+
python_version = "3.10"
|
app.py
CHANGED
@@ -1,19 +1,60 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
import os
|
4 |
-
from torch import autocast
|
5 |
-
from diffusers import StableDiffusionPipeline
|
6 |
from moviepy.editor import AudioFileClip, ImageClip
|
7 |
from pathlib import Path
|
8 |
-
|
|
|
|
|
9 |
|
10 |
output_dir = Path("temp/")
|
11 |
output_dir.mkdir(exist_ok=True, parents=True)
|
12 |
os.chdir(output_dir)
|
13 |
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
image = get_stable_diffusion_image(prompt)
|
|
|
|
|
|
|
17 |
video = add_static_image_to_audio(image, audio)
|
18 |
return video
|
19 |
|
@@ -47,6 +88,14 @@ def get_stable_diffusion_image(prompt):
|
|
47 |
|
48 |
|
49 |
iface = gr.Interface(
|
50 |
-
fn=process_inputs,
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
)
|
|
|
|
|
52 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
|
|
|
|
3 |
from moviepy.editor import AudioFileClip, ImageClip
|
4 |
from pathlib import Path
|
5 |
+
import subprocess
|
6 |
+
import uuid
|
7 |
+
import shutil
|
8 |
|
9 |
output_dir = Path("temp/")
|
10 |
output_dir.mkdir(exist_ok=True, parents=True)
|
11 |
os.chdir(output_dir)
|
12 |
|
13 |
|
14 |
+
class SpotifyApi:
|
15 |
+
spotify_directory = Path(output_dir / "spotify")
|
16 |
+
final_directory = output_dir
|
17 |
+
|
18 |
+
def __init__(self):
|
19 |
+
self.setup_spotipy
|
20 |
+
|
21 |
+
def setup_spotipy(self):
|
22 |
+
# Check if the credentials file exists
|
23 |
+
if not os.path.exists("spotif.rc"):
|
24 |
+
with open("spotify.rc", "w") as f:
|
25 |
+
f.write(
|
26 |
+
f"{os.environ['SPOTIFY_USERNAME']} {os.environ['SPOTIFY_PASSWORD']}"
|
27 |
+
)
|
28 |
+
subprocess.call(["spodcast", "-l", "spotify.rc"])
|
29 |
+
else:
|
30 |
+
pass
|
31 |
+
|
32 |
+
def download_episode(self, episode_url):
|
33 |
+
# Generate a 8 character random string
|
34 |
+
foldername = str(uuid.uuid4())[:8]
|
35 |
+
out_path = (self.spotify_directory / foldername).resolve()
|
36 |
+
subprocess.call(["spodcast", "--root-path", out_path, episode_url])
|
37 |
+
self.foldername = foldername
|
38 |
+
return self.get_final_mp3()
|
39 |
+
|
40 |
+
def get_final_mp3(self):
|
41 |
+
# Look in all the subdirectories of spotify for the mp3 file
|
42 |
+
for root, dirs, files in os.walk(Path(self.spotify_directory / self.foldername)):
|
43 |
+
for file in files:
|
44 |
+
if file.endswith(".mp3"):
|
45 |
+
final_mp3 = Path(self.final_directory / self.foldername).with_suffix(
|
46 |
+
".mp3"
|
47 |
+
)
|
48 |
+
shutil.copy(os.path.join(root, file), final_mp3)
|
49 |
+
shutil.rmtree(Path(self.spotify_directory / self.foldername))
|
50 |
+
return final_mp3.as_posix()
|
51 |
+
|
52 |
+
|
53 |
+
def process_inputs(prompt, audio, spotify_url):
|
54 |
image = get_stable_diffusion_image(prompt)
|
55 |
+
if spotify_url:
|
56 |
+
spotify = SpotifyApi()
|
57 |
+
audio = spotify.download_episode(spotify_url)
|
58 |
video = add_static_image_to_audio(image, audio)
|
59 |
return video
|
60 |
|
|
|
88 |
|
89 |
|
90 |
iface = gr.Interface(
|
91 |
+
fn=process_inputs,
|
92 |
+
inputs=[
|
93 |
+
gr.Textbox(label="Describe your podcast clip"),
|
94 |
+
gr.Audio(type="filepath", label="Upload an mp3"),
|
95 |
+
gr.Textbox(label="Or Paste a spotify episode link"),
|
96 |
+
],
|
97 |
+
outputs="video",
|
98 |
)
|
99 |
+
|
100 |
+
|
101 |
iface.launch()
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ nvidia-ml-py3
|
|
4 |
ftfy
|
5 |
--extra-index-url https://download.pytorch.org/whl/cu113 torch
|
6 |
moviepy
|
7 |
-
gradio
|
|
|
|
4 |
ftfy
|
5 |
--extra-index-url https://download.pytorch.org/whl/cu113 torch
|
6 |
moviepy
|
7 |
+
gradio
|
8 |
+
spodcast
|