danicor commited on
Commit
9bdd7e9
·
verified ·
1 Parent(s): 2685cbe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import whisper
3
+ import tempfile
4
+ import os
5
+
6
+ model = whisper.load_model("large-v3")
7
+
8
+ def transcribe_audio(audio_file):
9
+ if audio_file is None:
10
+ return {"error": "No audio file provided"}
11
+
12
+ try:
13
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
14
+ tmp_file.write(audio_file)
15
+ tmp_file_path = tmp_file.name
16
+
17
+ result = model.transcribe(tmp_file_path)
18
+
19
+ os.unlink(tmp_file_path)
20
+
21
+ return {"text": result["text"]}
22
+
23
+ except Exception as e:
24
+ return {"error": str(e)}
25
+
26
+ iface = gr.Interface(
27
+ fn=transcribe_audio,
28
+ inputs=gr.File(type="binary"),
29
+ outputs=gr.JSON(),
30
+ api_name="transcribe"
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ iface.launch()