AirusMaqbool commited on
Commit
86408ff
·
verified ·
1 Parent(s): f52d562

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ import gradio as gr
3
+ import json
4
+ import tempfile
5
+ import os
6
+
7
+ print("Loading Whisper model...")
8
+ # Load model when space starts
9
+ model = whisper.load_model("base")
10
+ print("Model loaded successfully!")
11
+
12
+ def transcribe_audio(audio_file):
13
+ """
14
+ Simple function to transcribe audio to text
15
+ """
16
+ try:
17
+ print(f"Processing audio file: {audio_file}")
18
+
19
+ # Transcribe the audio
20
+ result = model.transcribe(audio_file)
21
+
22
+ print("Transcription completed successfully!")
23
+
24
+ # Return as JSON string
25
+ return json.dumps({
26
+ "text": result["text"],
27
+ "language": result["language"],
28
+ "status": "success"
29
+ })
30
+
31
+ except Exception as e:
32
+ print(f"Error: {str(e)}")
33
+ return json.dumps({
34
+ "error": str(e),
35
+ "status": "failed"
36
+ })
37
+
38
+ # Create a simple web interface
39
+ demo = gr.Interface(
40
+ fn=transcribe_audio,
41
+ inputs=gr.Audio(sources=["upload"], type="filepath", label="Upload Audio File"),
42
+ outputs=gr.Textbox(label="Transcription Result", lines=5),
43
+ title=" Whisper Transcription API",
44
+ description="Upload an audio file to convert it to text using OpenAI's Whisper model.",
45
+ examples=[
46
+ ["https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/1.flac"],
47
+ ["https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/2.flac"]
48
+ ]
49
+ )
50
+
51
+ # Launch the application
52
+ if __name__ == "__main__":
53
+ demo.launch(debug=True, share=True)