Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
gr.load("models/distil-whisper/distil-large-v2").launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
3 |
+
|
4 |
+
processor = WhisperProcessor.from_pretrained("distil-whisper/distil-large-v2")
|
5 |
+
model = WhisperForConditionalGeneration.from_pretrained("distil-whisper/distil-large-v2")
|
6 |
+
|
7 |
+
def transcrire_audio(audio, prompt):
|
8 |
+
input_features = processor(audio, return_tensors="pt").input_features
|
9 |
+
|
10 |
+
output_without_prompt = model.generate(input_features)
|
11 |
+
transcription_sans_prompt = processor.decode(output_without_prompt[0])
|
12 |
+
|
13 |
+
prompt_ids = processor.get_prompt_ids(prompt)
|
14 |
+
output_with_prompt = model.generate(input_features, prompt_ids=prompt_ids)
|
15 |
+
transcription_avec_prompt = processor.decode(output_with_prompt[0])
|
16 |
+
|
17 |
+
return {
|
18 |
+
"Transcription sans prompt": transcription_sans_prompt,
|
19 |
+
"Transcription avec prompt": transcription_avec_prompt
|
20 |
+
}
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=transcrire_audio,
|
24 |
+
inputs=["audio", "text"],
|
25 |
+
outputs=["text", "text"],
|
26 |
+
live=True,
|
27 |
+
interpretation="default"
|
28 |
+
)
|
29 |
+
|
30 |
+
iface.launch()
|
31 |
|
|