254 commited on
Commit
d3df9be
·
verified ·
1 Parent(s): f6b6e9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -43
app.py CHANGED
@@ -1,52 +1,23 @@
1
- import whisper
2
  import gradio as gr
3
- import time
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
- # Function to transcribe audio and generate a word cloud
13
- def transcribe_and_generate_wordcloud(audio):
14
  # Transcribe the audio file
15
- result = model.transcribe(audio) # Changed audio.name to 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
- interface = gr.Interface(
44
- fn=transcribe_and_generate_wordcloud,
45
- inputs=gr.Audio(type="filepath"), # Change type to "filepath"
46
- outputs=[gr.Textbox(label="Transcribed Text"), gr.Image(label="Word Cloud")],
47
- title="Local Language Transcription and Word Cloud Generator",
48
- description="Upload an audio file in a local language to transcribe it and visualize the text as a word cloud."
 
49
  )
50
 
51
- # Launch the Gradio app
52
- interface.launch()
 
 
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()