awacke1's picture
Update app.py
8cc02de
raw
history blame
5.62 kB
import gradio as gr
import moviepy.video.io.ImageSequenceClip
from PIL import Image
from pydub import AudioSegment
from moviepy.editor import *
import numpy as np
import mutagen
from mutagen.mp3 import MP3
import cv2
def resize(img_list):
resize_img_list = []
for item in img_list:
im = Image.open(item)
imResize = im.resize((256,256), Image.ANTIALIAS)
resize_img_list.append(np.array(imResize))
return resize_img_list
def merge_audio_video(entities_num, resize_img_list, text_input):
speech = text2speech(text_input)
wav_audio = AudioSegment.from_file(speech, "flac") #("/content/gdrive/My Drive/AI/audio1.flac", "flac")
wav_audio.export("audio.mp3", format="mp3") #("/content/gdrive/My Drive/AI/audio1.mp3", format="mp3")
audio_length = int(MP3("audio.mp3").info.length)
fps= entities_num / audio_length #length of audio file
fps = float(format(fps, '.5f'))
clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(resize_img_list, fps=fps)
clip.write_videofile('my_vid_tmp.mp4')
videoclip = VideoFileClip('my_vid_tmp.mp4') #("/content/gdrive/My Drive/AI/my_video1.mp4")
audioclip = AudioFileClip('audio.mp3') #.subclip(0, 15)
mergedclip = videoclip.set_audio(audioclip)
duration = mergedclip.duration
frame_count = mergedclip.fps
return mergedclip
fastspeech = gr.Interface.load("huggingface/facebook/fastspeech2-en-ljspeech")
def text2speech(text):
speech = fastspeech(text)
return speech
def engine(text_input):
ner = gr.Interface.load("huggingface/flair/ner-english-ontonotes-large")
entities = ner(text_input)
entities = [tupl for tupl in entities if None not in tupl]
entities_num = len(entities)
img_list = []
for ent in entities:
img = gr.Interface.load("spaces/multimodalart/latentdiffusion")(ent[0],'50','256','256','1',10)[0]
img_list.append(img)
resize_img_list = resize(img_list)
mergedclip = merge_audio_video(entities_num, resize_img_list, text_input)
mergedclip.to_videofile('mergedvideo.mp4')
return 'mergedvideo.mp4'
app = gr.Interface(engine,
gr.inputs.Textbox(lines=5, label="Input Text"),
gr.outputs.Video(type=None, label='Final Merged video'),
description="<div>๐ŸŽญ๐ŸŽž๏ธ๐Ÿฟ AI Movie Maker - Comedy ๐ŸŽฌ ๐Ÿง  ๐ŸŽจ</div>" ,
examples=
[
["Two space marines named Liev Schreiber and Will Sasso take up arms to save the planet from an alien invasion. These two dashing strong men play a comedic role in the science fiction movie of the future where even barnaby bunny is willing to join their wacky gang of space marines to save the planet with good looks and comedy."],
["Portland book editor Natalie Holland has chosen the wrong guy another underachiever once again. With her life going nowhere fast, she accepts a job offer from publisher and friend Avery Goldstein and moves to Los Angeles. A woman of depth and principle, Portland chic Natalie is a fish out of water in LA. Things only get worse when she learns shes been hired to edit the latest romance novel from bestselling author Beverly Wilcox, a powerful, glamorous and intimidating figure straight out of The Devil Wears Prada."],
["This is a story about a guy who is willing to sell the soul, just to dial million views for your videos on YouTube. On the way to his goal, he turns into a fast train Moscow - Vladivostokยป, where faced with an American actress, suffering aerophobia. On the way strangers expect such adventures that they lag behind the train that trying to catch up, moving our unpredictable and fabulous Mother Russia - After each of them need to be in Vladivostok exactly 7 days - for reasons which they carefully conceal from each other."],
["Moritaka Mashiro (Takeru Satoh) doesnt want to follow in the path of his uncle who worked as a manga artist, but ultimately died because of exhaustion. Moritaka Mashiro figures he will graduate from school and work at an office. Things change though when falls in love with a girl at school. The girl, who hopes to become a voice actress, tells Moritaka they can marry, but only after they both achieve their dreams. Moritaka then teams up with fellow classmate Akito Takagi (Ryunosuke Kamiki) to publish their first manga."],
["With Blue Mountain State football star Thad Castle recently signing a multi-million dollar NFL contract, his teammates and college life seem like a distant memory. However, when a new school dean threatens to clean up the BMS image by auctioning off the infamous Goat House, Alex, Sammy and the boys must find a way to convince him to get involved. Despite his new fortune and fame, there is one small favor that Thad needs done before he saves the day: the biggest booze-and-sloot fest in BMS history. Welcome to Thadland!"],
["Two friends, Michael Director and actor Rodrigo, receive the grand prize of the jury in a trendy international film festival. After too much drink, Rodrigo signed a contract to participate in the upcoming film of the filmmaker. Miguel disappears and reappears ten years later with a proposal to make a long delirious. Rodrigo is already famous and distrusts the health director. To make matters worse, you realize that to honor the contract will be required to make a film that can destroy not only his career but his life."]
],
title="AI Pipeline Multi Model ๐ŸŽญ๐ŸŽž๏ธ๐Ÿฟ Movie Maker ๐ŸŽฌ ๐Ÿง  ๐ŸŽจ",
article="<br><div></div>"
).launch(enable_queue=True, debug=True)