TIMBOVILL commited on
Commit
e66305d
·
verified ·
1 Parent(s): 9bb0840

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import random
3
  import gradio as gr
4
  from groq import Groq
5
  from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip
 
6
 
7
  # Initialize client with API key
8
  client = Groq(
@@ -47,6 +48,10 @@ def generate_response(prompt, history, model, temperature, max_tokens, top_p, se
47
  return response
48
 
49
  # Process video function
 
 
 
 
50
  def process_video(text):
51
  video_folder = "videos"
52
  video_files = [os.path.join(video_folder, f) for f in os.listdir(video_folder) if f.endswith(('mp4', 'mov', 'avi', 'mkv'))]
@@ -57,7 +62,16 @@ def process_video(text):
57
  video = VideoFileClip(selected_video)
58
  start_time = random.uniform(0, max(0, video.duration - 60))
59
  video = video.subclip(start_time, min(start_time + 60, video.duration))
60
- video = video.resize(height=1920).crop(x1=video.w // 2 - 540, x2=video.w // 2 + 540)
 
 
 
 
 
 
 
 
 
61
 
62
  text_lines = text.split()
63
  text = "\n".join([" ".join(text_lines[i:i+8]) for i in range(0, len(text_lines), 8)])
 
3
  import gradio as gr
4
  from groq import Groq
5
  from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip
6
+ import numpy as np
7
 
8
  # Initialize client with API key
9
  client = Groq(
 
48
  return response
49
 
50
  # Process video function
51
+ from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip
52
+ from PIL import Image
53
+
54
+ # Adjusting MoviePy's resize function to use Image.LANCZOS directly
55
  def process_video(text):
56
  video_folder = "videos"
57
  video_files = [os.path.join(video_folder, f) for f in os.listdir(video_folder) if f.endswith(('mp4', 'mov', 'avi', 'mkv'))]
 
62
  video = VideoFileClip(selected_video)
63
  start_time = random.uniform(0, max(0, video.duration - 60))
64
  video = video.subclip(start_time, min(start_time + 60, video.duration))
65
+
66
+ # Manually resize using PIL to avoid the issue
67
+ def resize_image(image, new_size):
68
+ pil_image = Image.fromarray(image)
69
+ resized_pil = pil_image.resize(new_size[::-1], Image.LANCZOS)
70
+ return np.array(resized_pil)
71
+
72
+ new_size = (1080, int(video.h * (1080 / video.w)))
73
+ video = video.fl_image(lambda image: resize_image(image, new_size))
74
+ video = video.crop(x1=video.w // 2 - 540, x2=video.w // 2 + 540)
75
 
76
  text_lines = text.split()
77
  text = "\n".join([" ".join(text_lines[i:i+8]) for i in range(0, len(text_lines), 8)])