| | import torch |
| | import gradio as gr |
| | from PIL import Image |
| | import scipy.io.wavfile as wavfile |
| |
|
| | |
| | from transformers import pipeline |
| |
|
| | |
| |
|
| | |
| | |
| |
|
| | device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') |
| |
|
| | narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs") |
| |
|
| | |
| |
|
| | |
| |
|
| | |
| | caption_image = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large", device=device) |
| |
|
| | |
| |
|
| | |
| | |
| |
|
| | |
| | def generate_audio(text): |
| |
|
| | |
| | narrated_text = narrator(text) |
| |
|
| | |
| | wavfile.write("output.wav", rate=narrated_text["sampling_rate"], |
| | data=narrated_text["audio"][0]) |
| | |
| | |
| | return "output.wav" |
| |
|
| |
|
| | def caption_my_image(pil_image): |
| |
|
| | semantics = caption_image(pil_image)[0]["generated_text"] |
| | audio = generate_audio(semantics) |
| |
|
| | return audio |
| |
|
| |
|
| | gr.close_all() |
| |
|
| | demo = gr.Interface(fn=caption_my_image, |
| | inputs=[gr.Image(label="Select Image", type="pil")], |
| | outputs=[gr.Audio(label="Generated Audio")], |
| | title="@IT AI Enthusiast (https://www.youtube.com/@itaienthusiast/) - Project 8: Image Captioning with AI", |
| | description="THIS APPLICATION WILL BE USED TO CAPTION IMAGES WITH THE HELP OF AI") |
| |
|
| | demo.launch() |
| |
|