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

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

@ -4,7 +4,6 @@ import os
import re
from os.path import exists
from typing import Tuple, Any
from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip
from moviepy.audio.io.AudioFileClip import AudioFileClip
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.ffmpeg_tools import ffmpeg_extract_subclip
from rich.console import Console
from rich.progress import track
from utils import settings
from utils.cleanup import cleanup
from utils.console import print_step, print_substep
from utils.video import Video
from utils.videos import save_data
from utils import settings
console = Console()
W, H = 1080, 1920
W, H = 1080,1920
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"))
elif settings.config["settings"]["storymodemethod"] == 1:
#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"))
else:
@ -119,7 +119,7 @@ def make_final_video(
.set_opacity(float(opacity)),
)
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(
ImageClip(f"assets/temp/{id}/png/img{i}.png")
.set_duration(audio_clips[i + 1].duration)
@ -142,7 +142,9 @@ def make_final_video(
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
final = CompositeVideoClip([background_clip, image_concat])
title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"])

Loading…
Cancel
Save