AudioToImage / app.py
Bartusito's picture
Update app.py
48decfb
raw
history blame
983 Bytes
import gradio as gr
import torch
import huggingsound
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
from transformers import SpeechRecognitionModel
def modelo1(audio):
model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-large-xlsr-53-english")
transcriptions = model.transcribe(audio)
return transcriptions
def modelo2(text):
model_id = "stabilityai/stable-diffusion-2-1"
# Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")
image = pipe(text).images[0]
return image
def execution(audio):
modelo1res = modelo1(audio)
modelo2res = modelo2(modelo1res)
return modelo2res
if __name__ == "__main__":
demo = gr.Interface(fn=execution, inputs="audio", outputs="image")
demo.launch()