Spaces:
Sleeping
Sleeping
254
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
import gradio as gr
|
3 |
+
import time
|
4 |
+
|
5 |
+
# Load the Whisper model
|
6 |
+
model = whisper.load_model("base")
|
7 |
+
|
8 |
+
# Function to transcribe audio and return sentences with a delay
|
9 |
+
def transcribe_audio(audio):
|
10 |
+
# Transcribe the audio file
|
11 |
+
result = model.transcribe(audio.name)
|
12 |
+
|
13 |
+
# Split the transcription into sentences
|
14 |
+
sentences = result["text"].split(". ")
|
15 |
+
|
16 |
+
# Print each sentence on a new line with a short delay
|
17 |
+
output = []
|
18 |
+
for sentence in sentences:
|
19 |
+
if sentence.strip(): # Check if the sentence is not empty
|
20 |
+
output.append(sentence.strip() + ".")
|
21 |
+
time.sleep(2) # Add a short delay before printing the next sentence
|
22 |
+
return "\n".join(output)
|
23 |
+
|
24 |
+
# Gradio interface
|
25 |
+
interface = gr.Interface(
|
26 |
+
fn=transcribe_audio,
|
27 |
+
inputs=gr.Audio(source="upload", type="file"),
|
28 |
+
outputs="text",
|
29 |
+
title="Whisper Transcription with Delay",
|
30 |
+
description="Upload an audio file to transcribe and display each sentence with a short delay."
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch the Gradio app
|
34 |
+
interface.launch()
|