feat:Added AI based sentence processing

pull/1288/head
Syed Aman Raza 2 years ago committed by GitHub
parent d1b3b68e83
commit 764530e664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,8 @@
from PIL import Image, ImageDraw,ImageFont from PIL import Image, ImageDraw,ImageFont
import textwrap import textwrap
import re import re
from rich.progress import track
def draw_multiple_line_text(image, text, font, text_color,padding): def draw_multiple_line_text(image, text, font, text_color,padding):
''' '''
Draw multiline text over given image Draw multiline text over given image
@ -27,7 +29,7 @@ def imagemaker( theme,reddit_obj,
size=(500,176) size=(500,176)
textcolor=txtclr textcolor=txtclr
for idx,text in enumerate(texts): for idx,text in track(enumerate(texts),'Rendering Imaging..'):
image =Image.new('RGBA',size,theme) image =Image.new('RGBA',size,theme)
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
if len(text)>50: if len(text)>50:

@ -1,46 +1,24 @@
import re
MAX_CHARACTER= 200 import spacy
#working good #working good
def posttextparser(obj): def posttextparser(obj):
text=obj#["thread_post"]
newtext=[]
# for text in text:
if len(text)>MAX_CHARACTER:
text2=text.split("\n")
for dot in text2:
if len(dot)>MAX_CHARACTER:
text3=dot.split(".")
for comma in text3:
if len(comma)> MAX_CHARACTER:
text4=comma.split(',')
newtext.extend(text4)
else:
newtext.append(comma)
else:
newtext.append(dot)
else:
newtext.append(text)
return remover(newtext)
def remover(List): text=re.sub("\n", "", obj )
reg=['',' ','.','\n',')',"''",'"',"'",'"','""'] #add if any any unwant value found
lines=List try:
lines1=[] nlp=spacy.load('en_core_web_sm')
lines2=[] except OSError :
for item in lines: print("dev:please dowload the model with this command \npython -m spacy download en")
for r in reg : exit()
if item==r:
break
else:
continue
else:
lines1.append(item)
for a in lines1: #Double check doc= nlp(text)
if a!='':
aa=a.strip() newtext=[]
lines2.append(aa)
# print(f'"{a}"') for line in doc.sents:
return lines2 newtext.append(line.text)
# print(line)
return newtext

@ -4,7 +4,6 @@ import os
import re import re
from os.path import exists from os.path import exists
from typing import Tuple, Any from typing import Tuple, Any
from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip
from moviepy.audio.io.AudioFileClip import AudioFileClip from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.video.VideoClip import ImageClip from moviepy.video.VideoClip import ImageClip
@ -13,15 +12,16 @@ from moviepy.video.compositing.concatenate import concatenate_videoclips
from moviepy.video.io.VideoFileClip import VideoFileClip from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from rich.console import Console from rich.console import Console
from rich.progress import track
from utils import settings
from utils.cleanup import cleanup from utils.cleanup import cleanup
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils.video import Video from utils.video import Video
from utils.videos import save_data from utils.videos import save_data
from utils import settings
console = Console() console = Console()
W, H = 1080, 1920 W, H = 1080,1920
def name_normalize(name: str) -> str: def name_normalize(name: str) -> str:
@ -83,7 +83,7 @@ def make_final_video(
audio_clips.insert(1,AudioFileClip(f"assets/temp/{id}/mp3/postaudio.mp3")) audio_clips.insert(1,AudioFileClip(f"assets/temp/{id}/mp3/postaudio.mp3"))
elif settings.config["settings"]["storymodemethod"] == 1: elif settings.config["settings"]["storymodemethod"] == 1:
#here work is not done14 #here work is not done14
audio_clips = [AudioFileClip(f"assets/temp/{id}/mp3/postaudio-{i}.mp3") for i in range(number_of_clips+1)] audio_clips = [AudioFileClip(f"assets/temp/{id}/mp3/posttext-{i}.mp3") for i in track(range(number_of_clips+1),"Collecting the audio files...")]
audio_clips.insert(0, AudioFileClip(f"assets/temp/{id}/mp3/title.mp3")) audio_clips.insert(0, AudioFileClip(f"assets/temp/{id}/mp3/title.mp3"))
else: else:
@ -119,7 +119,7 @@ def make_final_video(
.set_opacity(float(opacity)), .set_opacity(float(opacity)),
) )
elif settings.config["settings"]["storymodemethod"] == 1: elif settings.config["settings"]["storymodemethod"] == 1:
for i in range(0, number_of_clips+1): for i in track(range(0, number_of_clips+1),"Collecting the image files..."):
image_clips.append( image_clips.append(
ImageClip(f"assets/temp/{id}/png/img{i}.png") ImageClip(f"assets/temp/{id}/png/img{i}.png")
.set_duration(audio_clips[i + 1].duration) .set_duration(audio_clips[i + 1].duration)
@ -142,7 +142,9 @@ def make_final_video(
img_clip_pos = background_config[3] img_clip_pos = background_config[3]
image_concat = concatenate_videoclips(image_clips).set_position(img_clip_pos) # note transition kwarg for delay in imgs image_concat = concatenate_videoclips(image_clips).set_position(
img_clip_pos
) # note transition kwarg for delay in imgs
image_concat.audio = audio_composite image_concat.audio = audio_composite
final = CompositeVideoClip([background_clip, image_concat]) final = CompositeVideoClip([background_clip, image_concat])
title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"]) title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"])

Loading…
Cancel
Save