whispy commited on
Commit
0742ded
β€’
1 Parent(s): a7406eb

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +67 -0
  2. packages.txt +1 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import DiffusionPipeline
4
+ from transformers import (
5
+ WhisperForConditionalGeneration,
6
+ WhisperProcessor,
7
+ pipeline,
8
+ )
9
+
10
+ import os
11
+ MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
12
+
13
+ device = "cuda" if torch.cuda.is_available() else "cpu"
14
+ model = WhisperForConditionalGeneration.from_pretrained("whispy/whisper_italian").to(device)
15
+ processor = WhisperProcessor.from_pretrained("whispy/whisper_italian")
16
+
17
+ pipe = pipeline(model="whispy/whisper_italian")
18
+
19
+ diffuser_pipeline = DiffusionPipeline.from_pretrained(
20
+ "CompVis/stable-diffusion-v1-4",
21
+ custom_pipeline="speech_to_image_diffusion",
22
+ speech_model="whispy/whisper_italian",
23
+ speech_processor=processor,
24
+ use_auth_token=MY_SECRET_TOKEN,
25
+ revision="fp16",
26
+ torch_dtype=torch.float16,
27
+ )
28
+
29
+ diffuser_pipeline.enable_attention_slicing()
30
+ diffuser_pipeline = diffuser_pipeline.to(device)
31
+
32
+ def transcribe(audio):
33
+ text = pipe(audio)["text"]
34
+ return text
35
+
36
+
37
+ #β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
38
+ # GRADIO SETUP
39
+ title = "Speech to Diffusion β€’ Community Pipeline"
40
+ description = """
41
+ <p style='text-align: center;'>This demo can generate an image from an audio sample using pre-trained OpenAI whisper-small and Stable Diffusion.<br />
42
+ Community examples consist of both inference and training examples that have been added by the community.<br />
43
+ <a href='https://github.com/huggingface/diffusers/tree/main/examples/community#speech-to-image' target='_blank'> Click here for more information about community pipelines </a>
44
+ </p>
45
+ """
46
+ article = """
47
+ <p style='text-align: center;'>Community pipeline by Mikail Duzenli β€’ Gradio demo by Sylvain Filoni & Ahsen Khaliq<p>
48
+ """
49
+ audio_input = gr.Audio(source="microphone", type="filepath")
50
+ image_output = gr.Image()
51
+
52
+ def speech_to_text(audio_sample):
53
+
54
+ #process_audio = whisper.load_audio(audio_sample)
55
+ process_audio = transcribe(audio_sample)
56
+ output = diffuser_pipeline(process_audio)
57
+
58
+ print(f"""
59
+ β€”β€”β€”β€”β€”β€”β€”β€”
60
+ output: {output}
61
+ β€”β€”β€”β€”β€”β€”β€”β€”
62
+ """)
63
+
64
+ return output.images[0]
65
+
66
+ demo = gr.Interface(fn=speech_to_text, inputs=audio_input, outputs=image_output, title=title, description=description, article=article)
67
+ demo.launch()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ pytube
4
+ sentencepiece