Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
from transformers import
|
| 3 |
-
from diffusers import StableDiffusionPipeline
|
| 4 |
-
import torch
|
| 5 |
-
import librosa
|
| 6 |
-
import matplotlib.pyplot as plt
|
| 7 |
-
import os
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# 1. Modèle Speech-to-Text (Wav2Vec2)
|
| 12 |
-
model_name_stt = "facebook/wav2vec2-large-960h"
|
| 13 |
-
processor = Wav2Vec2Processor.from_pretrained(model_name_stt)
|
| 14 |
-
model_stt = Wav2Vec2ForCTC.from_pretrained(model_name_stt)
|
| 15 |
-
|
| 16 |
-
# 2. Modèle Text-to-Image (Stable Diffusion)
|
| 17 |
-
model_name_t2i = "CompVis/stable-diffusion-v1-4"
|
| 18 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_name_t2i)
|
| 19 |
-
pipe.to("cuda") # Si tu as une GPU, sinon utilise "cpu"
|
| 20 |
-
|
| 21 |
-
# Fonction Speech-to-Text (STT)
|
| 22 |
-
def speech_to_text(audio_file):
|
| 23 |
-
# Charger l'audio et le convertir au format compatible
|
| 24 |
-
audio_input, _ = librosa.load(audio_file, sr=16000)
|
| 25 |
-
input_values = processor(audio_input, return_tensors="pt", sampling_rate=16000).input_values
|
| 26 |
-
logits = model_stt(input_values).logits
|
| 27 |
-
predicted_ids = torch.argmax(logits, dim=-1)
|
| 28 |
-
transcription = processor.decode(predicted_ids[0])
|
| 29 |
-
return transcription
|
| 30 |
-
|
| 31 |
-
# Fonction Text-to-Image (T2I)
|
| 32 |
-
def text_to_image(prompt):
|
| 33 |
-
image = pipe(prompt).images[0]
|
| 34 |
-
return image
|
| 35 |
-
|
| 36 |
-
# Fonction pour générer une diapositive à partir d'un fichier audio
|
| 37 |
-
def generate_slide(audio_file):
|
| 38 |
-
# Convertir l'audio en texte (STT)
|
| 39 |
-
transcription = speech_to_text(audio_file)
|
| 40 |
-
|
| 41 |
-
# Utiliser le texte pour générer une image (T2I)
|
| 42 |
-
image = text_to_image(transcription)
|
| 43 |
-
|
| 44 |
-
# Sauvegarder l'image en tant que diapositive
|
| 45 |
-
slide_path = "slide.png"
|
| 46 |
-
image.save(slide_path)
|
| 47 |
-
|
| 48 |
-
# Retourner la transcription et la diapo générée
|
| 49 |
-
return transcription, slide_path
|
| 50 |
-
|
| 51 |
-
# Interface utilisateur avec Gradio
|
| 52 |
-
def create_gradio_interface():
|
| 53 |
-
with gr.Blocks() as demo:
|
| 54 |
-
gr.Markdown("## Générateur de Diapositives - Speech to Text et Text to Image")
|
| 55 |
-
|
| 56 |
-
# Input: audio
|
| 57 |
-
audio_input = gr.Audio(label="Télécharger un fichier audio", source="upload", type="filepath")
|
| 58 |
-
|
| 59 |
-
# Output: transcription et image générée
|
| 60 |
-
transcription_output = gr.Textbox(label="Texte Transcrit")
|
| 61 |
-
image_output = gr.Image(label="Image Générée")
|
| 62 |
-
|
| 63 |
-
# Bouton pour lancer la génération
|
| 64 |
-
submit_btn = gr.Button("Générer la Diapositive")
|
| 65 |
-
|
| 66 |
-
# Fonction associée au bouton
|
| 67 |
-
submit_btn.click(fn=generate_slide, inputs=audio_input, outputs=[transcription_output, image_output])
|
| 68 |
-
|
| 69 |
-
return demo
|
| 70 |
-
|
| 71 |
-
# Lancer l'interface
|
| 72 |
-
if __name__ == "__main__":
|
| 73 |
-
demo = create_gradio_interface()
|
| 74 |
-
demo.launch()
|
|
|
|
| 1 |
+
# Load model directly
|
| 2 |
+
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
processor = AutoProcessor.from_pretrained("openai/whisper-large-v3")
|
| 5 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained("openai/whisper-large-v3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|