Spaces:
Sleeping
Sleeping
Update process_energy.py
Browse files- process_energy.py +46 -21
process_energy.py
CHANGED
|
@@ -167,8 +167,35 @@ def activate_transfer():
|
|
| 167 |
new_mp = recipient_mp + transferred_mp
|
| 168 |
return new_mp
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
# Fungsi untuk membuat video afirmasi dengan audio
|
| 171 |
-
def
|
| 172 |
# Texts for the video
|
| 173 |
texts = [
|
| 174 |
f"HAI {nama_anda.upper()}! DENGARLAH SUARA ENERGI SEMESTA DIGITAL SELAMA 3 MENIT AGAR PROSES TRANSFER BERJALAN MULUS.",
|
|
@@ -177,37 +204,35 @@ def create_affirmation_frames(tujuan, nama_anda):
|
|
| 177 |
f"SAYA, {nama_anda.upper()}, MENARIK HAL-HAL POSITIF DALAM HIDUP SAYA. SAYA AKAN MENCAPAI TUJUAN SAYA SUKSES DI: {tujuan.upper()}",
|
| 178 |
]
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
font = ImageFont.truetype("arial.ttf", 24) # Pastikan path font sesuai dengan environment Anda
|
| 183 |
-
|
| 184 |
-
for text in texts:
|
| 185 |
-
img = Image.new('RGB', (width, height), color=(0, 0, 0))
|
| 186 |
-
d = ImageDraw.Draw(img)
|
| 187 |
-
lines = text.split(' ')
|
| 188 |
-
line_length = 4
|
| 189 |
-
formatted_text = '\n'.join([' '.join(lines[i:i + line_length]) for i in range(0, len(lines, line_length))])
|
| 190 |
-
d.text((width / 2, height / 2), formatted_text, font=font, fill=(255, 255, 255), align="center", anchor="mm")
|
| 191 |
-
frames.extend([np.array(img)] * 150) # 150 frames untuk 5 detik dengan 30 fps
|
| 192 |
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
clip = ImageSequenceClip(frames, fps=30)
|
| 198 |
|
| 199 |
-
# Load background
|
| 200 |
-
background_clip = VideoFileClip("spin_energy.gif").subclip(0, 2).fx(loop, duration=
|
| 201 |
|
| 202 |
# Load the generated audio file
|
| 203 |
audio_clip = AudioFileClip(audio_filename)
|
| 204 |
|
| 205 |
# Concatenate text clips with background
|
| 206 |
-
video = CompositeVideoClip([background_clip
|
| 207 |
-
video = video.set_duration(
|
| 208 |
|
| 209 |
# Write the result to a file
|
| 210 |
video.write_videofile(output_filename, fps=24, codec='libx264')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
"""
|
| 212 |
def create_affirmation_video_with_audio(tujuan, nama_anda, audio_filename, output_filename="affirmation_video.mp4"):
|
| 213 |
# Texts for the video
|
|
|
|
| 167 |
new_mp = recipient_mp + transferred_mp
|
| 168 |
return new_mp
|
| 169 |
|
| 170 |
+
# Fungsi untuk membuat frame gambar afirmasi
|
| 171 |
+
def create_affirmation_frames(texts, width=640, height=480, duration=5):
|
| 172 |
+
frames = []
|
| 173 |
+
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf" # Path font default
|
| 174 |
+
font_size = 24
|
| 175 |
+
|
| 176 |
+
for text in texts:
|
| 177 |
+
frame = Image.new("RGB", (width, height), color="black")
|
| 178 |
+
draw = ImageDraw.Draw(frame)
|
| 179 |
+
|
| 180 |
+
# Menggunakan font default
|
| 181 |
+
try:
|
| 182 |
+
font = ImageFont.truetype(font_path, font_size)
|
| 183 |
+
except IOError:
|
| 184 |
+
font = ImageFont.load_default()
|
| 185 |
+
|
| 186 |
+
lines = text.split('\n')
|
| 187 |
+
y_text = height // 2 - (len(lines) * font_size) // 2
|
| 188 |
+
for line in lines:
|
| 189 |
+
width_text, height_text = draw.textsize(line, font=font)
|
| 190 |
+
draw.text(((width - width_text) / 2, y_text), line, font=font, fill="white")
|
| 191 |
+
y_text += height_text
|
| 192 |
+
|
| 193 |
+
frames.append(frame)
|
| 194 |
+
|
| 195 |
+
return frames
|
| 196 |
+
|
| 197 |
# Fungsi untuk membuat video afirmasi dengan audio
|
| 198 |
+
def create_affirmation_video_with_audio(tujuan, nama_anda, audio_filename, output_filename="affirmation_video.mp4"):
|
| 199 |
# Texts for the video
|
| 200 |
texts = [
|
| 201 |
f"HAI {nama_anda.upper()}! DENGARLAH SUARA ENERGI SEMESTA DIGITAL SELAMA 3 MENIT AGAR PROSES TRANSFER BERJALAN MULUS.",
|
|
|
|
| 204 |
f"SAYA, {nama_anda.upper()}, MENARIK HAL-HAL POSITIF DALAM HIDUP SAYA. SAYA AKAN MENCAPAI TUJUAN SAYA SUKSES DI: {tujuan.upper()}",
|
| 205 |
]
|
| 206 |
|
| 207 |
+
# Create frames
|
| 208 |
+
frames = create_affirmation_frames(texts, width=640, height=480)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
+
# Save frames as images and load into a video
|
| 211 |
+
image_filenames = []
|
| 212 |
+
for i, frame in enumerate(frames):
|
| 213 |
+
image_filename = f"frame_{i}.png"
|
| 214 |
+
frame.save(image_filename)
|
| 215 |
+
image_filenames.append(image_filename)
|
| 216 |
|
| 217 |
+
# Load images as video clips
|
| 218 |
+
clips = [ImageClip(m).set_duration(duration) for m in image_filenames]
|
|
|
|
| 219 |
|
| 220 |
+
# Load background GIF and loop it
|
| 221 |
+
background_clip = VideoFileClip("spin_energy.gif").subclip(0, 2).fx(loop, duration=len(clips) * duration)
|
| 222 |
|
| 223 |
# Load the generated audio file
|
| 224 |
audio_clip = AudioFileClip(audio_filename)
|
| 225 |
|
| 226 |
# Concatenate text clips with background
|
| 227 |
+
video = CompositeVideoClip([background_clip] + clips)
|
| 228 |
+
video = video.set_duration(len(clips) * duration).set_audio(audio_clip)
|
| 229 |
|
| 230 |
# Write the result to a file
|
| 231 |
video.write_videofile(output_filename, fps=24, codec='libx264')
|
| 232 |
+
|
| 233 |
+
# Remove temporary image files
|
| 234 |
+
for image_filename in image_filenames:
|
| 235 |
+
os.remove(image_filename)
|
| 236 |
"""
|
| 237 |
def create_affirmation_video_with_audio(tujuan, nama_anda, audio_filename, output_filename="affirmation_video.mp4"):
|
| 238 |
# Texts for the video
|