254 commited on
Commit
2de1bff
1 Parent(s): d3df9be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import gradio as gr
2
  import whisper
 
 
 
3
 
4
  # Load the Whisper model
5
  model = whisper.load_model("base")
@@ -7,17 +10,25 @@ model = whisper.load_model("base")
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()
 
 
1
  import gradio as gr
2
  import whisper
3
+ from wordcloud import WordCloud
4
+ import tempfile
5
+ import os
6
 
7
  # Load the Whisper model
8
  model = whisper.load_model("base")
 
10
  def transcribe(audio):
11
  # Transcribe the audio file
12
  result = model.transcribe(audio)
13
+ text = result['text']
14
+
15
+ # Generate a word cloud
16
+ wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
17
+
18
+ # Save the word cloud image to a temporary file
19
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmpfile:
20
+ wordcloud.to_file(tmpfile.name)
21
+ return text, tmpfile.name
22
 
23
  # Create the Gradio interface
 
24
  demo = gr.Interface(
25
  fn=transcribe,
26
+ inputs=gr.Audio(type="filepath"), # Allow file uploads
27
+ outputs=["text", gr.Image(type="filepath")], # Output both text and image
28
  title="Audio Transcription App",
29
+ description="Upload an audio file to transcribe it to text and view a word cloud of the text."
30
  )
31
 
32
  # Launch the app
33
+ if __name__ == "__main__":
34
+ demo.launch()