Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Install required libraries
|
2 |
+
# Uncomment the line below if you are running locally to install dependencies
|
3 |
+
# !pip install gradio openai-whisper
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import whisper
|
7 |
+
|
8 |
+
# Load Whisper model
|
9 |
+
model = whisper.load_model("large")
|
10 |
+
|
11 |
+
# Define transcription function
|
12 |
+
def transcribe_audio(audio):
|
13 |
+
"""
|
14 |
+
Transcribes the uploaded audio file into text.
|
15 |
+
"""
|
16 |
+
try:
|
17 |
+
# Transcribe the audio
|
18 |
+
result = model.transcribe(audio.name)
|
19 |
+
transcription = result["text"]
|
20 |
+
return transcription
|
21 |
+
except Exception as e:
|
22 |
+
return f"Error transcribing audio: {str(e)}"
|
23 |
+
|
24 |
+
# Gradio Interface
|
25 |
+
interface = gr.Interface(
|
26 |
+
fn=transcribe_audio,
|
27 |
+
inputs=gr.Audio(source="upload", type="filepath", label="Upload your audio file"),
|
28 |
+
outputs=gr.Textbox(label="Transcribed Text"),
|
29 |
+
title="AI Audio Transcriber",
|
30 |
+
description=(
|
31 |
+
"Upload an audio file, and this AI will transcribe the content into text. "
|
32 |
+
"Powered by OpenAI Whisper, it supports most languages."
|
33 |
+
),
|
34 |
+
theme="compact"
|
35 |
+
)
|
36 |
+
|
37 |
+
# Launch the interface
|
38 |
+
if __name__ == "__main__":
|
39 |
+
interface.launch(share=True)
|