Kaiyeee commited on
Commit
3d5c597
·
verified ·
1 Parent(s): 89c92b7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import soundfile as sf
3
+ from transformers import AutoProcessor, pipeline
4
+ from optimum.intel.openvino import OVModelForSpeechSeq2Seq
5
+
6
+ # Load model + processor
7
+ model_id = "distil-whisper/distil-large-v2"
8
+ processor = AutoProcessor.from_pretrained(model_id)
9
+ ov_model = OVModelForSpeechSeq2Seq.from_pretrained(model_id, export=True)
10
+ ov_model.generation_config.max_new_tokens = 128
11
+
12
+ # Create HF pipeline
13
+ pipe = pipeline(
14
+ "automatic-speech-recognition",
15
+ model=ov_model,
16
+ tokenizer=processor.tokenizer,
17
+ feature_extractor=processor.feature_extractor,
18
+ chunk_length_s=15,
19
+ batch_size=16,
20
+ )
21
+
22
+ # Transcription function
23
+ def transcribe(audio):
24
+ audio_array, sampling_rate = sf.read(audio)
25
+ result = pipe(audio_array)
26
+ return result["text"]
27
+
28
+ # Launch Gradio UI
29
+ gr.Interface(
30
+ fn=transcribe,
31
+ inputs=gr.Audio(type="filepath"),
32
+ outputs="text",
33
+ title="🧠 Distil-Whisper + OpenVINO ASR",
34
+ description="Upload audio to transcribe using Distil-Whisper accelerated with Intel OpenVINO.",
35
+ ).launch()