Spaces:
Runtime error
Runtime error
Commit
·
baa52ab
1
Parent(s):
5f93a34
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,16 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import tempfile
|
| 4 |
-
from moviepy.editor import ImageSequenceClip
|
| 5 |
from PIL import Image
|
| 6 |
import torch
|
| 7 |
from diffusers import AudioLDMPipeline
|
| 8 |
from transformers import AutoProcessor, ClapModel, BlipProcessor, BlipForConditionalGeneration
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# make Space compatible with CPU duplicates
|
| 11 |
if torch.cuda.is_available():
|
| 12 |
device = "cuda"
|
|
@@ -22,14 +26,10 @@ pipe.unet = torch.compile(pipe.unet)
|
|
| 22 |
|
| 23 |
# CLAP model (only required for automatic scoring)
|
| 24 |
clap_model = ClapModel.from_pretrained("sanchit-gandhi/clap-htsat-unfused-m-full").to(device)
|
| 25 |
-
|
| 26 |
|
| 27 |
generator = torch.Generator(device)
|
| 28 |
|
| 29 |
-
# Charger le modèle et le processeur Blip pour la description d'images
|
| 30 |
-
image_caption_processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 31 |
-
image_caption_model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 32 |
-
|
| 33 |
# Streamlit app setup
|
| 34 |
st.set_page_config(
|
| 35 |
page_title="Text to Media",
|
|
@@ -55,12 +55,12 @@ if uploaded_files:
|
|
| 55 |
f.write(uploaded_file.read())
|
| 56 |
image_paths.append(image_path)
|
| 57 |
|
| 58 |
-
#
|
| 59 |
try:
|
| 60 |
image = Image.open(image_path).convert("RGB")
|
| 61 |
-
inputs =
|
| 62 |
-
out =
|
| 63 |
-
caption =
|
| 64 |
descriptions.append(caption)
|
| 65 |
except Exception as e:
|
| 66 |
descriptions.append("Erreur lors de la génération de la légende")
|
|
@@ -79,7 +79,7 @@ if uploaded_files:
|
|
| 79 |
n_candidates = st.slider("Number waveforms to generate", 1, 3, 3, 1)
|
| 80 |
|
| 81 |
def score_waveforms(text, waveforms):
|
| 82 |
-
inputs =
|
| 83 |
inputs = {key: inputs[key].to(device) for key in inputs}
|
| 84 |
with torch.no_grad():
|
| 85 |
logits_per_text = clap_model(**inputs).logits_per_text # this is the audio-text similarity score
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import tempfile
|
| 4 |
+
from moviepy.editor import ImageSequenceClip, concatenate_videoclips
|
| 5 |
from PIL import Image
|
| 6 |
import torch
|
| 7 |
from diffusers import AudioLDMPipeline
|
| 8 |
from transformers import AutoProcessor, ClapModel, BlipProcessor, BlipForConditionalGeneration
|
| 9 |
|
| 10 |
+
# Charger le modèle et le processeur Blip
|
| 11 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 12 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 13 |
+
|
| 14 |
# make Space compatible with CPU duplicates
|
| 15 |
if torch.cuda.is_available():
|
| 16 |
device = "cuda"
|
|
|
|
| 26 |
|
| 27 |
# CLAP model (only required for automatic scoring)
|
| 28 |
clap_model = ClapModel.from_pretrained("sanchit-gandhi/clap-htsat-unfused-m-full").to(device)
|
| 29 |
+
audio_processor = AutoProcessor.from_pretrained("sanchit-gandhi/clap-htsat-unfused-m-full")
|
| 30 |
|
| 31 |
generator = torch.Generator(device)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Streamlit app setup
|
| 34 |
st.set_page_config(
|
| 35 |
page_title="Text to Media",
|
|
|
|
| 55 |
f.write(uploaded_file.read())
|
| 56 |
image_paths.append(image_path)
|
| 57 |
|
| 58 |
+
# Générer la légende pour chaque image
|
| 59 |
try:
|
| 60 |
image = Image.open(image_path).convert("RGB")
|
| 61 |
+
inputs = processor(image, return_tensors="pt")
|
| 62 |
+
out = model.generate(**inputs)
|
| 63 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 64 |
descriptions.append(caption)
|
| 65 |
except Exception as e:
|
| 66 |
descriptions.append("Erreur lors de la génération de la légende")
|
|
|
|
| 79 |
n_candidates = st.slider("Number waveforms to generate", 1, 3, 3, 1)
|
| 80 |
|
| 81 |
def score_waveforms(text, waveforms):
|
| 82 |
+
inputs = audio_processor(text=text, audios=list(waveforms), return_tensors="pt", padding=True)
|
| 83 |
inputs = {key: inputs[key].to(device) for key in inputs}
|
| 84 |
with torch.no_grad():
|
| 85 |
logits_per_text = clap_model(**inputs).logits_per_text # this is the audio-text similarity score
|