Spaces:
Runtime error
Runtime error
Siddiqui Qamar
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import whisper
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Load the Whisper model
|
| 6 |
+
model = whisper.load_model("base")
|
| 7 |
+
|
| 8 |
+
def transcribe_audio(audio_file):
|
| 9 |
+
# Transcribe the audio
|
| 10 |
+
result = model.transcribe(audio_file.name)
|
| 11 |
+
|
| 12 |
+
# Get the base name of the file (without extension) for the output file
|
| 13 |
+
output_filename = os.path.splitext(os.path.basename(audio_file.name))[0] + ".txt"
|
| 14 |
+
|
| 15 |
+
# Save the transcript to a text file with the same name as the input file
|
| 16 |
+
with open(output_filename, "w") as text_file:
|
| 17 |
+
text_file.write(result["text"])
|
| 18 |
+
|
| 19 |
+
return result["text"], output_filename
|
| 20 |
+
|
| 21 |
+
# Create Gradio interface
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=transcribe_audio,
|
| 24 |
+
inputs=gr.File(label="Upload Audio File"),
|
| 25 |
+
outputs=[
|
| 26 |
+
gr.Textbox(label="Transcription"),
|
| 27 |
+
gr.File(label="Download Transcript")
|
| 28 |
+
],
|
| 29 |
+
title="Audio Transcription Tool",
|
| 30 |
+
description="Upload an audio file (WAV, MP3, etc.) to get its transcription. The transcript will be displayed and available for download."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Launch the interface
|
| 34 |
+
iface.launch()
|