Spaces:
Runtime error
Runtime error
Commit
·
07eb64a
1
Parent(s):
8568ae2
Update app.py
Browse files
app.py
CHANGED
@@ -41,8 +41,11 @@ st.title("Générateur de Diaporama Vidéo et Musique")
|
|
41 |
# Sélectionnez les images
|
42 |
uploaded_files = st.file_uploader("Sélectionnez des images (PNG, JPG, JPEG)", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
43 |
|
|
|
|
|
|
|
44 |
if uploaded_files:
|
45 |
-
#
|
46 |
temp_dir = tempfile.mkdtemp()
|
47 |
|
48 |
# Enregistrez les images téléchargées dans le répertoire temporaire
|
@@ -69,6 +72,28 @@ if uploaded_files:
|
|
69 |
for i, image_path in enumerate(image_paths):
|
70 |
st.image(image_path, caption=f"Description : {descriptions[i]}", use_column_width=True)
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# Générez de la musique à partir des descriptions
|
73 |
st.header("Génération de Musique à partir des Descriptions")
|
74 |
|
@@ -78,24 +103,24 @@ if uploaded_files:
|
|
78 |
|
79 |
# Configuration de la musique
|
80 |
seed = st.number_input("Seed", value=45)
|
81 |
-
|
82 |
guidance_scale = st.slider("Guidance scale", 0.0, 4.0, 2.5, 0.5)
|
83 |
-
n_candidates = st.slider("
|
84 |
|
85 |
def score_waveforms(text, waveforms):
|
86 |
inputs = processor(text=text, audios=list(waveforms), return_tensors="pt", padding=True)
|
87 |
inputs = {key: inputs[key].to(device) for key in inputs}
|
88 |
with torch.no_grad():
|
89 |
-
logits_per_text = clap_model(**inputs).logits_per_text
|
90 |
-
probs = logits_per_text.softmax(dim=-1)
|
91 |
-
most_probable = torch.argmax(probs)
|
92 |
waveform = waveforms[most_probable]
|
93 |
return waveform
|
94 |
|
95 |
if st.button("Générer de la musique"):
|
96 |
waveforms = pipe(
|
97 |
music_input,
|
98 |
-
audio_length_in_s=
|
99 |
guidance_scale=guidance_scale,
|
100 |
num_inference_steps=100,
|
101 |
num_waveforms_per_prompt=n_candidates if n_candidates else 1,
|
@@ -107,34 +132,17 @@ if uploaded_files:
|
|
107 |
else:
|
108 |
waveform = waveforms[0]
|
109 |
|
110 |
-
#
|
111 |
-
|
112 |
-
|
113 |
-
# Créer une vidéo à partir des images
|
114 |
-
st.header("Génération du Diaporama Vidéo")
|
115 |
-
|
116 |
-
# Configuration du diaporama
|
117 |
-
image_duration = st.slider("Duration (seconds) des images dans le diaporama", 1, 10, 4)
|
118 |
-
|
119 |
-
if st.button("Créer le Diaporama Vidéo"):
|
120 |
-
def create_video(images, output_video_path):
|
121 |
-
frame_rate = 1 / image_duration
|
122 |
-
|
123 |
-
image_clips = [ImageSequenceClip([image], fps=frame_rate, durations=[image_duration]) for image in images]
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
final_clip.write_videofile(output_video_path, codec='libx264', fps=frame_rate)
|
128 |
-
|
129 |
-
output_video_path = os.path.join(temp_dir, "slideshow.mp4")
|
130 |
-
create_video(image_paths, output_video_path)
|
131 |
-
|
132 |
-
# Afficher la vidéo
|
133 |
-
st.video(open(output_video_path, 'rb').read())
|
134 |
|
135 |
# Supprimer le répertoire temporaire
|
136 |
for image_path in image_paths:
|
137 |
os.remove(image_path)
|
138 |
os.remove(output_video_path)
|
|
|
139 |
os.rmdir(temp_dir)
|
140 |
|
|
|
41 |
# Sélectionnez les images
|
42 |
uploaded_files = st.file_uploader("Sélectionnez des images (PNG, JPG, JPEG)", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
43 |
|
44 |
+
# Sélection de la durée d'affichage de chaque image avec une barre horizontale (en secondes)
|
45 |
+
image_duration = st.slider("Sélectionnez la durée d'affichage de chaque image (en secondes)", 1, 10, 4)
|
46 |
+
|
47 |
if uploaded_files:
|
48 |
+
# Créer un répertoire temporaire pour stocker les images
|
49 |
temp_dir = tempfile.mkdtemp()
|
50 |
|
51 |
# Enregistrez les images téléchargées dans le répertoire temporaire
|
|
|
72 |
for i, image_path in enumerate(image_paths):
|
73 |
st.image(image_path, caption=f"Description : {descriptions[i]}", use_column_width=True)
|
74 |
|
75 |
+
# Créer une vidéo à partir des images
|
76 |
+
if image_paths:
|
77 |
+
output_video_path = os.path.join(temp_dir, "slideshow.mp4")
|
78 |
+
|
79 |
+
# Débit d'images par seconde (calculé en fonction de la durée de chaque image)
|
80 |
+
frame_rate = 1 / image_duration
|
81 |
+
|
82 |
+
image_clips = [ImageSequenceClip([image_path], fps=frame_rate, durations=[image_duration]) for image_path in image_paths]
|
83 |
+
|
84 |
+
final_clip = concatenate_videoclips(image_clips, method="compose")
|
85 |
+
|
86 |
+
final_clip.write_videofile(output_video_path, codec='libx264', fps=frame_rate)
|
87 |
+
|
88 |
+
# Afficher la vidéo
|
89 |
+
st.video(open(output_video_path, 'rb').read())
|
90 |
+
|
91 |
+
# Supprimer le répertoire temporaire
|
92 |
+
for image_path in image_paths:
|
93 |
+
os.remove(image_path)
|
94 |
+
os.remove(output_video_path)
|
95 |
+
os.rmdir(temp_dir)
|
96 |
+
|
97 |
# Générez de la musique à partir des descriptions
|
98 |
st.header("Génération de Musique à partir des Descriptions")
|
99 |
|
|
|
103 |
|
104 |
# Configuration de la musique
|
105 |
seed = st.number_input("Seed", value=45)
|
106 |
+
music_duration = st.slider("Durée de la musique (en secondes)", 10, 180, 60, 10)
|
107 |
guidance_scale = st.slider("Guidance scale", 0.0, 4.0, 2.5, 0.5)
|
108 |
+
n_candidates = st.slider("Nombre de formes d'onde à générer", 1, 3, 3, 1)
|
109 |
|
110 |
def score_waveforms(text, waveforms):
|
111 |
inputs = processor(text=text, audios=list(waveforms), return_tensors="pt", padding=True)
|
112 |
inputs = {key: inputs[key].to(device) for key in inputs}
|
113 |
with torch.no_grad():
|
114 |
+
logits_per_text = clap_model(**inputs).logits_per_text
|
115 |
+
probs = logits_per_text.softmax(dim=-1)
|
116 |
+
most_probable = torch.argmax(probs)
|
117 |
waveform = waveforms[most_probable]
|
118 |
return waveform
|
119 |
|
120 |
if st.button("Générer de la musique"):
|
121 |
waveforms = pipe(
|
122 |
music_input,
|
123 |
+
audio_length_in_s=music_duration,
|
124 |
guidance_scale=guidance_scale,
|
125 |
num_inference_steps=100,
|
126 |
num_waveforms_per_prompt=n_candidates if n_candidates else 1,
|
|
|
132 |
else:
|
133 |
waveform = waveforms[0]
|
134 |
|
135 |
+
# Sauvegardez la musique générée dans un fichier temporaire
|
136 |
+
music_temp_path = os.path.join(temp_dir, "generated_music.wav")
|
137 |
+
waveform.save(music_temp_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
+
# Afficher le lecteur audio
|
140 |
+
st.audio(open(music_temp_path, 'rb').read(), format="audio/wav", sample_rate=16000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
# Supprimer le répertoire temporaire
|
143 |
for image_path in image_paths:
|
144 |
os.remove(image_path)
|
145 |
os.remove(output_video_path)
|
146 |
+
os.remove(music_temp_path)
|
147 |
os.rmdir(temp_dir)
|
148 |
|