Nepjune commited on
Commit
79954be
·
verified ·
1 Parent(s): 8893dd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import BlipProcessor, BlipForConditionalGeneration
3
- from pydub import AudioSegment
4
- from pydub.playback import play
5
 
6
  model_id = "dblasko/blip-dalle3-img2prompt"
7
  model = BlipForConditionalGeneration.from_pretrained(model_id)
@@ -21,10 +21,11 @@ def generate_caption(image):
21
 
22
  return generated_caption, audio_path
23
 
24
-
25
  def play_audio(audio_path):
26
- sound = AudioSegment.from_file(audio_path)
27
- play(sound)
 
 
28
 
29
  # Create a Gradio interface with an image input, a textbox output, a button, and an audio player
30
  demo = gr.Interface(
@@ -37,4 +38,3 @@ demo = gr.Interface(
37
  ]
38
  )
39
  demo.launch()
40
-
 
1
  import gradio as gr
2
  from transformers import BlipProcessor, BlipForConditionalGeneration
3
+ from gtts import gTTS
4
+ import pygame
5
 
6
  model_id = "dblasko/blip-dalle3-img2prompt"
7
  model = BlipForConditionalGeneration.from_pretrained(model_id)
 
21
 
22
  return generated_caption, audio_path
23
 
 
24
  def play_audio(audio_path):
25
+ pygame.mixer.init()
26
+ pygame.mixer.music.load(audio_path)
27
+ pygame.mixer.music.play()
28
+ pygame.event.wait()
29
 
30
  # Create a Gradio interface with an image input, a textbox output, a button, and an audio player
31
  demo = gr.Interface(
 
38
  ]
39
  )
40
  demo.launch()