Spaces:
Sleeping
Sleeping
254
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,23 @@
|
|
1 |
-
import whisper
|
2 |
import gradio as gr
|
3 |
-
import
|
4 |
-
from wordcloud import WordCloud
|
5 |
-
import matplotlib.pyplot as plt
|
6 |
-
import io
|
7 |
-
import base64
|
8 |
|
9 |
# Load the Whisper model
|
10 |
model = whisper.load_model("base")
|
11 |
|
12 |
-
|
13 |
-
def transcribe_and_generate_wordcloud(audio):
|
14 |
# Transcribe the audio file
|
15 |
-
result = model.transcribe(audio)
|
16 |
-
|
17 |
-
# Split the transcription into sentences
|
18 |
-
text = result["text"]
|
19 |
-
sentences = text.split(". ")
|
20 |
-
|
21 |
-
# Generate a word cloud
|
22 |
-
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
|
23 |
-
|
24 |
-
# Save the word cloud image to a BytesIO object
|
25 |
-
buffer = io.BytesIO()
|
26 |
-
plt.figure(figsize=(10, 5))
|
27 |
-
plt.imshow(wordcloud, interpolation='bilinear')
|
28 |
-
plt.axis('off')
|
29 |
-
plt.savefig(buffer, format='png')
|
30 |
-
plt.close()
|
31 |
-
buffer.seek(0)
|
32 |
-
|
33 |
-
# Encode the image as a base64 string
|
34 |
-
img_str = base64.b64encode(buffer.getvalue()).decode()
|
35 |
-
|
36 |
-
# Create a delay for demonstration
|
37 |
-
output = "\n".join([s.strip() + "." for s in sentences if s.strip()])
|
38 |
-
time.sleep(2) # Add a short delay before processing the next part
|
39 |
-
|
40 |
-
return output, f"data:image/png;base64,{img_str}"
|
41 |
|
42 |
-
# Gradio interface
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
)
|
50 |
|
51 |
-
# Launch the
|
52 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import whisper
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Load the Whisper model
|
5 |
model = whisper.load_model("base")
|
6 |
|
7 |
+
def transcribe(audio):
|
|
|
8 |
# Transcribe the audio file
|
9 |
+
result = model.transcribe(audio)
|
10 |
+
return result['text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Create the Gradio interface
|
13 |
+
# Removed the 'source' parameter and set type to 'upload' for file uploads.
|
14 |
+
demo = gr.Interface(
|
15 |
+
fn=transcribe,
|
16 |
+
inputs=gr.Audio(type="filepath"),
|
17 |
+
outputs="text",
|
18 |
+
title="Audio Transcription App",
|
19 |
+
description="Upload an audio file or record your voice to transcribe it to text."
|
20 |
)
|
21 |
|
22 |
+
# Launch the app
|
23 |
+
demo.launch()
|