Vira21 commited on
Commit
0727af5
·
verified ·
1 Parent(s): dc3248b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -31
app.py CHANGED
@@ -2,35 +2,6 @@ import gradio as gr
2
  from transformers import pipeline
3
  import torch
4
 
5
- # Load the Whisper model pipeline for speech recognition with optimizations
6
- model_name = "Vira21/Whisper-Base-KhmerV2"
7
- whisper_pipeline = pipeline(
8
- "automatic-speech-recognition",
9
- model=model_name,
10
- device=0 if torch.cuda.is_available() else -1 # Use GPU if available, otherwise use CPU
11
- )
12
 
13
- def transcribe_audio(audio):
14
- try:
15
- # Process and transcribe the audio
16
- result = whisper_pipeline(audio)["text"]
17
- return result
18
- except Exception as e:
19
- # Handle errors and return an error message
20
- return f"An error occurred during transcription: {str(e)}"
21
-
22
- # Gradio Interface with optimizations
23
- interface = gr.Interface(
24
- fn=transcribe_audio,
25
- inputs=gr.Audio(type="filepath"),
26
- outputs="text",
27
- title="Whisper Khmer Speech-to-Text",
28
- description="Upload an audio file or record your voice to get the transcription in Khmer.",
29
- examples=[["Example Audio/126.wav"]],
30
- allow_flagging="never" # Disables flagging to save resources
31
- )
32
-
33
- # Launch the app with queue enabled for better handling on free CPU
34
- if __name__ == "__main__":
35
- interface.queue() # Enable asynchronous queuing for better performance
36
- interface.launch()
 
2
  from transformers import pipeline
3
  import torch
4
 
5
+ interface = gr.load("models/Vira21/Whisper-Base-KhmerV2")
 
 
 
 
 
 
6
 
7
+ interface.launch()