Spaces:
Build error
Build error
Siddiqui Qamar
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,33 +2,30 @@ 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 |
-
#
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 31 |
)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
iface.launch()
|
|
|
|
| 2 |
import whisper
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
model = whisper.load_model("base")
|
| 6 |
|
| 7 |
def transcribe_audio(audio_file):
|
| 8 |
+
# Check file size (e.g., 25MB limit)
|
| 9 |
+
if os.path.getsize(audio_file.name) > 25 * 1024 * 1024:
|
| 10 |
+
return "Error: File size exceeds 25MB limit.", None
|
| 11 |
+
|
| 12 |
result = model.transcribe(audio_file.name)
|
|
|
|
|
|
|
| 13 |
output_filename = os.path.splitext(os.path.basename(audio_file.name))[0] + ".txt"
|
| 14 |
|
|
|
|
| 15 |
with open(output_filename, "w") as text_file:
|
| 16 |
text_file.write(result["text"])
|
| 17 |
|
| 18 |
return result["text"], output_filename
|
| 19 |
|
|
|
|
| 20 |
iface = gr.Interface(
|
| 21 |
fn=transcribe_audio,
|
| 22 |
+
inputs=gr.File(label="Upload Audio File (Max 25MB)"),
|
| 23 |
outputs=[
|
| 24 |
gr.Textbox(label="Transcription"),
|
| 25 |
gr.File(label="Download Transcript")
|
| 26 |
],
|
| 27 |
title="Audio Transcription Tool",
|
| 28 |
+
description="Upload an audio file (WAV, MP3, etc.) up to 25MB to get its transcription. Please use responsibly."
|
| 29 |
)
|
| 30 |
|
| 31 |
+
iface.launch(share=True)
|
|
|