Spaces:
Runtime error
Runtime error
File size: 1,675 Bytes
9cc668b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
from PIL import Image
from transformers import pipeline
import scipy.io.wavfile as wavfile
import numpy as np
# import torch
# device = "cuda" if torch.cuda.is_available else "cpu"
# model_path = "C:/Users/ankitdwivedi/OneDrive - Adobe/Desktop/NLP Projects/Video to Text Summarization/Model/models--Salesforce--blip-image-captioning-large/snapshots/2227ac38c9f16105cb0412e7cab4759978a8fd90"
# caption_image = pipeline("image-to-text", model=model_path)
caption_image = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
# tts_model_path = "C:/Users/ankitdwivedi/OneDrive - Adobe/Desktop/NLP Projects/Video to Text Summarization/Model/models--kakao-enterprise--vits-ljs/snapshots/3bcb8321394f671bd948ebf0d086d694dda95464"
# Narrator = pipeline("text-to-speech", model=tts_model_path)
Narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
def generate_audio(text):
Narrated_Text = Narrator(text)
audio_data = np.array(Narrated_Text["audio"][0])
sampling_rate = Narrated_Text["sampling_rate"]
wavfile.write("generated_audio.wav", rate=sampling_rate, data=audio_data)
return "generated_audio.wav"
def caption_my_image(pil_image):
semantics = caption_image(images=pil_image)[0]["generated_text"]
return generate_audio(semantics)
demo = gr.Interface(fn=caption_my_image,
inputs=[gr.Image(label="Select Image",type="pil")],
outputs=[gr.Audio(label="Generated_Audio")],
title="Project 8: Audio Caption Image ",
description="THIS APPLICATION WILL BE USED TO provide Audio caption for the Image")
demo.launch() |